.newApply() ?
Brendan Eich
brendan at mozilla.org
Sat Nov 10 17:34:04 PST 2007
On Nov 10, 2007, at 5:17 PM, Garrett Smith wrote:
> I know it's too late for a proposal, but I keep wanting a couple of
> things for AOP stuff.
>
> One is a newApply
>
> Creational = {
> getByNode : function(el){
> if(!this.hasOwnProperty("instances")) this.instances = {};
> return this.instances.hasOwnProperty(el.id) && this.instances
> [el.id] ||
> (this.instances[el.id] = this.new.apply(arguments)); // <--
> Fictitious syntax.
> }
> }
>
> function Widget(el, dir){
>
> }
>
> Wiget.getByNode = Creational.getByNode; // Borrow the getByNode method
>
> So that way, I can have a Widget based on a node, yet still pass
> varargs to the constructor.
Got your back here ;-). Narcissus (http://lxr.mozilla.org/mozilla/
source/js/narcissus/) wants this too, and it's going to end up
falling out of the reflection APIs:
reflect::typeOf(this).reflect::construct(arguments)
or of course:
{ use namespace reflect;
. . . typeOf(this).constructo(arguments) }
in your example. The http://wiki.ecmascript.org/doku.php?
id=proposals:meta_objects proposal is out of date, it uses iterators
for the type and value parameters, but IIRC we have agreement to
satisfy your use-case. See http://bugs.ecmascript.org/ticket/232.
/be
More information about the Es4-discuss
mailing list