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

john larson johnlarsondev1 at gmail.com
Mon Mar 11 15:03:37 UTC 2019


*@Rob:* Thanks for pointing out "proposal-bind-operator". I examined the
proposal and as far as I understand, it is just another way to create a
bound enclosing function. What I am proposing is just the opposite, no
binding should take place in the enclosing function. A method call or usage
of a property should already have its lexical scope pointing to the class
instance and should not need any binding of its enclosing environment to
function correctly.

On Mon, Mar 11, 2019 at 4:57 PM Rob Ede <robjtede at icloud.com> wrote:

> I would imagine that this can be achieved with bind operator proposal,
> which already has Babel support, despite no examples showing usage inside a
> class.
>
> Something like:
> `oReq.addEventListener("load", ::this.responseHandler);`
> seems to be the syntax that will de-sugar to
> `oReq.addEventListener("load", this.responseHandler.bind(this));`
> to get you the desired this binding.
>
> I’m surprised this idea hasn't been mentioned yet although things have
> been moving slowly on that proposal and it seems to need some community
> support to move along.
>
> Regards,
> Rob
>
>
> References:
> 1: Bind Syntax Proposal (https://github.com/tc39/proposal-bind-operator)
> 2: Babel Plugin (
> https://babeljs.io/docs/en/next/babel-plugin-proposal-function-bind)
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190311/32cf5c34/attachment.html>


More information about the es-discuss mailing list