Syntactic sugar for using a function as if it were a method of its first argument

Jasper St. Pierre jstpierre at mecheye.net
Tue May 27 12:40:05 PDT 2014


>From my reading of the email and strawman page, let f = obj::foo; is
exactly equivalent to let f = foo.bind(obj);

Am I wrong? How is the result subtly different?

Really, with "obj::foo", I would expect "obj::foo" to be the same as
"obj.foo.bind(obj);", not "foo.bind(obj);" And even then, I don't think
it's worth it for a new syntax, since we already have the automatic method
closures for the new class syntax in ES6.


On Tue, May 27, 2014 at 3:29 PM, Brendan Eich <brendan at mozilla.org> wrote:

> Jasper St. Pierre wrote:
>
>> I'm not sure I like it. Given how other languages use the "::" operator,
>> I'd expect "Foo::bar" to do some sort of static property lookup for a name
>> called "bar" on "Foo", not bind the local variable "Foo" to the local
>> variable "bar".
>>
>
> That's not what the proposed bind operator does.
>
>
>  I think "bar.bind(Foo)" is more than enough.
>>
>
> That allocates a new (and subtly different) bound function object. Part of
> the motivation for the bind operator is to avoid the allocation (and the
> subtle difference, secondarily).
>
> /be
>



-- 
  Jasper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140527/a3d4c1c6/attachment.html>


More information about the es-discuss mailing list