Today I was reading the MDN documentation on Function.prototype.bind(). Under the section Bound functions used as constructors there is an example that I cannot quite unders
But how in the world can
new Point(17,42)
be an instance ofYAxisPoint
?
Because instanceof
works special with bound functions (those created from .bind()
calls). Usually it would check whether the object inherits from the constructors .prototype
, but bound functions don't have a .prototype
. Instead, when you use instanceof
on a bound function, it checks whether the object is an instance of the target function (that bind()
was called upon). So
… instanceof YAxisPoint
is exactly equivalent to
… instanceof Point
You can check this in the specs (ES5, ES6).