[[Invoke]] and implicit method calls

Tom Van Cutsem tomvc.be at gmail.com
Fri Sep 13 09:36:22 PDT 2013

MarkM and I talked about conditional invocation offline and we convinced
ourselves to argue for the status-quo (i.e. continue to encode conditional
invocations as [[Get]]+[[Call]]).

The most compelling argument we can think of is that [[Get]]+[[Call]] is
also the pattern JavaScript programmers use to express conditional method
calls today:

var f = obj[name];
if (f) { f.call(…); } else { … }

No matter whether or how we extend the MOP, such code exists and will
continue to exist, and well-designed proxies that want to re-bind |this|
must already deal with this pattern by implementing the "get" trap

We already have distinct "get" and "invoke" traps. Proxy writers must
already understand the dependency between these traps. Let's not make
things more complicated by adding a third, or by unnecessarily complicating
the signature of "invoke".

Given the status-quo, a proxy that wants to rebind |this| to the target
object must do so by overriding both "get" and "invoke". In the "invoke"
trap, |this|-rebinding is cheap (i.e. no need for bound functions). In the
"get" trap, it requires the handler to return a bound function (which
costs). But the cost will not be paid for ordinary method calls, which are
expected to be the common case.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130913/f43709c4/attachment.html>

More information about the es-discuss mailing list