Open raq929 opened 7 years ago
obj1.foo().call(someOtherObject)
That's an explicit binding, which is not what the quoted text is referring to.
Is the function called with a context (implicit binding)
I think the parenthetical is important. It should be a parenthetical.
I'm not sure when to re-emphasize that this
is not determined until the function is called. It's one of those things, like the definition of a callback, that I drill into them when I deliver this talk.
Binding isn't a very good word here, either.
Yeah. I drilled it too. Maybe that has to be enough?
Could we add
foo.call( obj2 ) // this === obj2
obj1.foo() // this === obj1
Also, could we not use the name foo
in different ways in this list (uncapitalized constructor function, method - key lookup in an object, a regular function, yada)?
After discussing with @gaand, the example would be more appropriately shown as:
obj1.foo() // this === obj1
obj1.foo.call( obj2 ) // this === obj2
The owning or containing object IS NOT NECESSARILY the context. You can call it in a different context using
obj1.foo().call(someOtherObject)
.I'm not quite sure how to reword this. It's not WRONG, but many people get confused and think that because an object contains a function,
this
is set to that object when it is written, not at runtime, and I want to be extremely clear about how that's not the case.