Re: Proposal For A New Alternative Keyword To “this” For Classes

Isiah Meadows isiahmeadows at gmail.com
Tue Mar 12 05:14:28 UTC 2019


I've done a little engine work, and inline caches work by inline type maps
based on the callee site. This *can* be used to reconstruct values +
receivers, but only when the value is constant. It is not sufficient to
ensure identity remains the same, and engines would still need a weak map
to link methods to instances (as opposed to prototypes).

It's worth noting not even Java or Ruby offers this - their method
references/objects (like our bound functions) are *not* memoized - they're
linked to classes, not instances. Python is the exception here in
auto-binding instance methods, not the norm.
On Mon, Mar 11, 2019 at 15:37 Bergi <a.d.bergi at web.de> wrote:

> Hi John!
> > I think the js run-time already has that information at hand, so as
> > long as we don't implement this as pure syntactical sugar, there would
> > not be a need to keep an extra reference to anything, because it would
> > be already there. The run-time will know which instance the invoked
> > method belongs to.
>
> Well no, you're wrong here: the runtime does not have this information
> at hand. In your example (simplified)
> ```
> var reqManager = new RequestManager();
> function addEventListener(f) {
>      console.log(f);
>      f(event);
> }
> addEventListener(reqManager.responseHandler);
> ```
> the `addEventListener` function will not know that the function `f` you
> passed was a method of the `reqManager` instance. It cannot distinguish
> that call from
> ```
> addEventListener(RequestManager.prototype.responseHandler);
> ```
> or
> ```
> var g = otherReqManager.responseHandler;
> addEventListener(g);
> ```
>
> It is exactly the same function that is passed in all three cases. There
> is no instance bound to `f`, and `f(event)` will not invoke it as a
> method (with a receiver/`this` value).
>
> Best regards,
>   Bergi
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190312/e6349725/attachment.html>


More information about the es-discuss mailing list