One question I have about Strong Mode classes: Can you guys provide a facility to create classes programmatically? Something like:Object.createClass(name, initializer, prototype)
function MakeC(parent, methodname) {return class extends parent { [methodname]() {} }}let C1 = MakeC(Object, 'foo')let C2 = MakeC(C1, 'bar')Does that help the kind of dynamism you need?Unfortunately it's not enough. I need an ability to construct a collection of methods dynamically to mimic Python metaclasses (which can alter methods, add new ones etc). I know that will make it almost impossible to statically analyze this kind of code, but that's something some users might be OK to sacrifice in order to be able to have more dynamism, along with other improvements of Strong Mode.
Even if I skip all metaclasses dance & magic, I would have another problem. Multiple inheritance applies some additional requirements on how 'super' works, i.e. I'll need to call a custom 'super' implementation. But I wouldn't be able to pass 'this' or do anything else with it besides accessing/assigning attributes in class' constructor. So I need a way to create classes in a bit less restrained way.Yury
--
You received this message because you are subscribed to the Google Groups "Strengthen JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to strengthen-j...@googlegroups.com.
To post to this group, send email to streng...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/strengthen-js/13bebb25-5704-4652-a1d1-b18eaf5575b1%40googlegroups.com.
On 11 March 2015 at 17:47, Yury Selivanov <yseli...@gmail.com> wrote:function MakeC(parent, methodname) {return class extends parent { [methodname]() {} }}let C1 = MakeC(Object, 'foo')let C2 = MakeC(C1, 'bar')Does that help the kind of dynamism you need?Unfortunately it's not enough. I need an ability to construct a collection of methods dynamically to mimic Python metaclasses (which can alter methods, add new ones etc). I know that will make it almost impossible to statically analyze this kind of code, but that's something some users might be OK to sacrifice in order to be able to have more dynamism, along with other improvements of Strong Mode.Of course, there always is 'eval'. Also, you can always use strong mode selectively, and for more dynamic stuff, call into a function or module that isn't in strong mode.But I'm not sure I understand how specifically your example relates to strong mode. As far as I can see, ES6 doesn't have any such reflective createClass mechanism regardless of mode (other than 'eval'). So this sounds more like an ES feature wish? If such a mechanism existed, I wouldn't see any particular reason to not make it available in strong mode.