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
correctly.

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.

Cheers,
Tom
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to