tc39 / proposal-bind-operator

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

Why bind to `this` and not pass as an argument? #31

Closed rstacruz closed 8 years ago

rstacruz commented 8 years ago

this is something that is mostly used in cases of prototypal inheritance, which is somewhat counter-intuitive to functional-programming-like approaches.

Instead of a::b() passing a as this to the b() function, why not pass it as the first parameter? that is:

"hello there world"
  :: titlecase()
  :: take(11)
  :: reverse()
  //=> "erehT olleH"

function titlecase (string) { ... }
function take (string, count) { return string.substr(0, count) }
function reverse (string) { return string.reverse() }

This is something that exists in elixir as the pipe operator.

benjamingr commented 8 years ago

This has been discussed over and over, both here and in ESDiscuss. Please read previous issues before opening new ones. https://github.com/zenparsing/es-function-bind/issues/19

benjamingr commented 8 years ago

In your case:

function take (count) { return this.substr(0, count) }
function reverse () { return this.split("").reverse().join(""); /* yours was broken*/ }

Etc.