Open stvkoch opened 7 years ago
This definitely doesn't relate to the bind operator, or to class properties - and I don't see why your last example is "ugly" either.
If you'd like to suggest a new change to the language, https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md may be helpful.
Semantically speaking... arrow functions define functions... not methods of classes.
Using the "ugly" way your code smell more like using workaround that a definition solution, strictly speaking
Strictly speaking, javascript only has functions. Not methods.
:) Strictly speaking about new ECMAScript standard library sorry
Now we support class and methods definitions, static variables,.. using syntactic sugar. I think, make sense we have one way to define methods of class with bind operators
@Alxandr I'm not sure what you mean by there are no methods. There are functions that bind this
as the object that they're being called on, which sounds like more or less the definition of a method if you ask me.
I would definitely like to see a method syntax for binding scope. The second example above is pretty confusing to read. Is it assigning a global? A local? No, it's assigning a member of the class... The first actually seems to have a consistent interface with the current javascript method syntax with an arrow to indicate lexical binding.
@mockdeep well, no. There are functions that bind this
to a lexical scope (ie, this
is whatever it was where the function was defined). It's not related to the object they are being called on at all (that's how normal functions in JS work), rather it's dependent on the scope where the function expression got executed. At the end of the day, it's basically just allowing this
to be bound by closures (just like any other variable in JS).
Maybe this is out of topic, but still, belongs to bind operator subject.
Why don't use arrow functions operation to create methods of classes with bind operators?
It's the same of: