Hi,

I've been thinking about Function proxy use cases lately. Things that
the spec do and that could be convenient to emulate as well or just
things that could be useful.
* [[Construct]]-less functions.
All Array.prototype methods are like that as well as all global object
methods (parseInt...) as well as a most of built-in methods. In some
way, if you want to define function which wouldn't make sense as
constructors (Math functions are a caricature of that),
[[Construct]]-less functions would be a good way to raise error if
someone, by accident, write "new blabla()" or even "new blabla".
It has been suggested here:
https://mail.mozilla.org/pipermail/es-discuss/2011-March/013019.html
I think that it was a bit too hacky. I would suggest more of a syntax like:
var pf = Proxy.createFunction({}, myCall, null);

* [[Call]]-less constructors
Already possible throughpf = Proxy.createFunction({}, null, myConstructor);

* "new A" behaves exactly like "A". This can be found for Arrays for
instance.
Already possible through pf = Proxy.createFunction({}, myCall, undefined);


Finally, I'd like to add a note on constructors. On the proposal is
written: "If no constructTrap is provided, new proxy(...args) is reified
as calling the proxy's callTrap with |this| bound to a new object
delegating to proxy.prototype".
In order to clarify, I think that instead of "proxy.prototype" it would
be better to say "the result of calling the get trap on the proxy with
argument 'prototype'". The get trap is the equivalent tothe [[Get]]
internal method used in ES5.1 13.2.2step 5.
Or maybe saying that the [[Construct]]algorithm (13.2.2) will be used.

David
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to