Proxies: get+fn vs. invoke

Brendan Eich brendan at mozilla.com
Wed Oct 13 20:36:43 PDT 2010


On Oct 13, 2010, at 5:14 PM, Brendan Eich wrote:

> Now consider if you had a third parameter to the 'get' trap to signal callee context vs. non-callee context. You'd still want to proxy the functions, that doesn't get simpler just due to a change of trap parameters. You'd still want to cache for identity. But you would have made invoke-only methods.

s/would/could/ in the last sentence -- the point is allowing get to tell when the property is being accessed as the callee in a call expression (or new expression? hmm) does not inevitably inject invoke only methods -- it simply adds the degree of freedom that someone could use to implement them.

Since there's no savings in terms of apples-to-apples method proxying and memoization ("caching") for ===, this degree of freedom seems strictly a misfeature. Even __noSuchMethod__ fans would agree!


> Ok, let's give up on functional programming and cached methods. Here' s my version written to use only __noSuchMethod__, no proxies:
> 
> function makeLazyMethodCloner(eager) {
>     return Object.create(Object.getPrototypeOf(eager), {
>         __noSuchMethod__: {
>             value: function (name, args) {
>                 return eager[name].apply(eager, arguments);

s/arguments/args/

I was testing lightly. Again, the code posted here works in a current mozilla-central or tracemonkey js shell, or (with s/print/console.log/g) in Firefox 4 betas.

/be

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20101013/26bc7f40/attachment-0001.html>


More information about the es-discuss mailing list