If you use the .bind result to create a new instance with new :
function TestClass(a,b,c,d) { } var TestClassBound = TestClass.bindMdn(null, 1, 2, 3); new TestClassBound();
Then this instanceof fNOP is true .
typeof this !== 'function' simply checks to see if it was called in a regular way on the function, and not using call or apply , or to make sure it was not copied to the prototype of other objects. So this only prevents something like
Function.prototype.bind.call("Not a function", 1, 2, 3);
or
var testObj = {}; testObj.bind = Function.prototype.bind; testObj.bind(1,2,3);
For every regular bind call, the typeof this function will always be a function .
So, typeof this !== 'function' should check if the bind object is called, really a function.
And this instanceof fNOP inside fBind ensures that the behavior is correct when the binding result is used.
source share