[[Invoke]] vs [[Get]]

Tom Van Cutsem tomvc.be at gmail.com
Mon Jun 10 01:18:59 PDT 2013

2013/6/9 Dmitry Soshnikov <dmitry.soshnikov at gmail.com>

> On Jun 8, 2013, at 3:30 AM, Till Schneidereit wrote:
> > At the last TC39 meeting, an agreement was reached for proxies to
> support an Invoke trap.
> Finally (I remember that long thread 2 years ago when I was advocating for
> it).
> Curious what was the reasoning behind this now, since as I understand the
> invoke trap wont' be for "virtual" (non-existing methods), but still for
> real function objects returned from the invoke trap -- in order to keep
> extracting to a var invariant working. If the later should be preserved,
> then the [[Get]] should be called anyways as I see.

The main reason behind adding invoke() was to make rebinding |this| easy
and efficient upon forwarding, essentially to make examples such as the
following work:

var date = new Date()
var proxy = new Proxy(date, {
  invoke: function(target, name, args, rcvr) {
    return target[name].apply(target, args); // note, |this| bound to
target inside forwarded method, not to |rcvr| (= the proxy itself)

proxy.getFullYear() // works fine, no "error: not a Date" exception

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

More information about the es-discuss mailing list