Re:ECMAScript bind operator proposal
by spion on Saturday December 10, 2016 @08:00PM
(#13148965)
The difference is that JS has no binding, yet it still allows for first class methods. Thus the OO "illusion" (object owns the methods) is broken: there are no methods, just functions that take an argument named `this`, in a slightly weird way, only when attached to records.
[ Parent
| on HN ]
Re:ECMAScript bind operator proposal
by groovy2shoes on Sunday December 11, 2016 @10:37PM
(#13155312)
> The difference is that JS has no binding ... just functions that take an argument named `this`
Associating a name with a value is precisely what binding is.
Frankly, though, I don't understand this comment at all. Care to clarify for me?
Re:ECMAScript bind operator proposal
by prodigal_erik on Sunday December 11, 2016 @10:44PM
(#13155358)
In Python
b = foo.bar
b()
correctly invokes the bar method of the foo object. In JavaScript, you have to write let b = foo.bar.bind(foo)
because foo.bar gives you a function (not a method) that doesn't remember which object it came from.
Re:ECMAScript bind operator proposal
by groovy2shoes on Tuesday December 13, 2016 @08:11PM
(#13172949)
I'm aware of what you have to write in JS, and I'd argue that that's the behavior that's to be expected. I'm actually more surprised by Python's behavior here. Lua works the same way JS does, as does Common Lisp.