tc39 / proposal-bind-operator

This-Binding Syntax for ECMAScript
1.74k stars 30 forks source link

Let's fix the semantics as implemented in Babel and move on. #32

Closed Artazor closed 8 years ago

Artazor commented 8 years ago

The only obstacle I see is the disagreement on whether

obj::f === obj::f   // ?

and

::obj.f === ::obj.f   // ?

I believe that the establishing equality is against the current (not ideal) implementation of Function.prototype.bind and will introduce inconsistency in the language.

Yes, it is an initial design flaw of the JavaScript that f.bind(obj) !== f.bind(obj).

In an ideal world there should be two separate methods

Function.prototype.bindThis = function (thisArg) { ... } 

and

Function.prototype.bindArgs = function (...args) { ... } 

Where bindThis binds only this and keeps normal arguments intact. And of course f.bindThis(obj) === f.bindThis(obj). And bindArgs that keeps this intact and performs a partial appliaction. And, of course, f.bindArgs(x,y,z) !== f.bindArgs(x,y,z).

The problem is that bindArgs and bindThis are conflated into bind by the initial design. @BrendanEich are you agree?

Now it is too late to split them apart. So the least painful solution is to agree that f.bind(obj) !== f.bind(obj) (reasonable sacrifice the memoization) and move on.

@zenparsing please don not give up!

benjamingr commented 8 years ago

The appropriate place to bring something like this up is esdiscuss and not here @Artazor

Artazor commented 8 years ago

Sorry for the offtopic, @benjamingr I've tried several times before this to subscribe to esdiscuss using https://mail.mozilla.org/subscribe/es-discuss

It replied on the website

Your subscription request has been received, and will soon be acted upon. 
Depending on the configuration of this mailing list, your subscription request
may have to be first confirmed by you via email, or approved by the list moderator.
If confirmation is required, you will soon get a confirmation email which contains 
further instructions.

And no further effect. No mails, no ability to write to the mail list... Should I write directly to @BrendanEich as it indicated that

es-discuss list run by brendan at mozilla.org, allen at wirfs-brock.com

?

zenparsing commented 8 years ago

@Artazor Thanks for your enthusiasm, and I haven't given up. I believe that the semantics for the Babel transform are exactly what you suggest, no?

WebReflection commented 8 years ago

I still believe like class is not just sugar and is not entirely replaceable by function, this operator could be something more than just .bind, something more needed, not just a shortcut.

I also agree this is not the place to discuss this, but I also don't understand what are your concerns @Artazor since AFAIK what you are saying is exactly the (IMO unfortunate) current status.

Artazor commented 8 years ago

@zenparsing, @WebReflection my proposal here is to sacrifice memoization. This proposal is based on the assumption that bind and apply will be never deprecated/changed (is it false assumption?) and we would need to learn two different ways how to solve the same problem (bind and ::)

Ok, I've finally subscribed to ES-discuss and will write there.