tc39 / proposal-bind-operator

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

Better to introduce self keyword #41

Open rangav opened 7 years ago

rangav commented 7 years ago

I think it's better to introduce self keyword for this as its already used in other languages like Swift and ruby. So it's easier to adopt.

:: is really terrible to use and looks ackward to read the syntax.

Please don't make JavaScript hard to read.

saschanaz commented 7 years ago

self is already used in web browser environment so it will be a big breaking change.

robotlolita commented 7 years ago

JS already has a self parameter, which we call this.

:: solves a different problem, namely invoking a function while providing an explicit this parameter (as in thisArgument::someFunction(other, args, here)someFunction.call(thisArgument, other, args, here)), and constructing a new function whose this parameter is bound (as in ::thisArgument.someFunctionthisArgument.someFunction.bind(thisArgument)).

As far as I know most languages don't allow you to provide an explicit this argument, since most languages don't allow you to get the method's function directly, so this isn't a problem that could exist in those languages. Python is one of the few exceptions that come to mind (as well as Lua and JavaScript, of course).

The :: operator is somewhat close to infix application in languages like F#, by the way, where arg1 |> someFunction(arg2) is the same as someFunction(arg1, arg2). The major difference is that it uses the implicit this parameter to pass that first argument, instead of the first positional argument.

azz commented 7 years ago

As @SaschaNaz mentioned, self is already a reference to the global object.

https://developer.mozilla.org/en/docs/Web/API/Window/self