Concise Method Binding

Andrea Giammarchi andrea.giammarchi at gmail.com
Thu Nov 12 07:46:34 UTC 2015


You basically demonstrated nobody read my comment in there months ago ;-)

https://github.com/zenparsing/es-function-bind/issues/17#issuecomment-120978833


Anyway, the security concern is non  existent to me, every method of every
instance of every class can  be a communication channel, everything bound
can be a communication channel, I don't see why ::obj.someMethod would be
different and  is not explained anywhere in there.

But since nobody read that thread anymore,  I guess it's pointless to even
keep writing in there.

Best Regards






On Wed, Nov 11, 2015 at 4:52 PM, Bergi <a.d.bergi at web.de> wrote:

> Andrea Giammarchi schrieb:
>
>> Just my thoughts, I wouldn't put any self-bound thing in the class and
>> rather improve that `::` proposal so that whenever you `obj::method` it
>> creates a uniquely bound callback so that `obj::method === obj::method`
>>
>
> This was considered:
> https://github.com/zenparsing/es-function-bind/issues/17 - it's quite
> unexpected that an operator would return the same result every time, and
> there are security considerations as well. Also it would be quite
> complicated to spec - how and where did you store the memoisation. Feel
> free to join the discussion!
>
> Using the `::` operator in the class declaration itself makes sense to me.
> It conveys "this method will always be bound" very effectively, and you
> wouldn't even need special syntax to access it.
> ```js
> class Xample {
>   ::myListener(…) {…}
> }
> ```
> should desugar to
> ```js
> class Xample {
>   // a getter on the prototype
>   get myListener() {
>     // with per-instance memoisation
>     return this.myListener = (…) => {
>       // that returns a bound method
>>     };
>   }
> }
> ```
> It might be equivalently done via a custom decorator of course:
> ```js
> class Xample {
>   @autobind
>   myListener(…) {…}
> }
> ```
>
> 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/20151112/62678704/attachment-0001.html>


More information about the es-discuss mailing list