myObj.myMethod();
Has different semantics than var x = myObj.myMethod;
x();
Which causes code like: myList.map(myObj.myMethod);
to behave somewhat unintuitively. myObj.myMethod();
Has different semantics than var x = myObj.myMethod;
x();
Which causes code like: myList.map(myObj.myMethod);
to behave somewhat unintuitively.Of course, late binding implies dynamic dispatch, but the reverse isn't true. On the other hand, almost every untyped OO language uses late binding (I can't even think of one that doesn't, off the top of my head...), as do some typed languages (those that target the .NET CLR, for example), so even with your stronger assertion JS far from unique in that regard.
That behavior is standard fare for OO. If anyone finds it tricky, I find it more likely that the struggling programmer has yet to internalize OO than that JS is doing something strange (in this particular case, I mean... JS does plenty of strange shit otherwise ;) ).
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?
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.