Function.prototype.bind and foo.bind refers to the same code?
Absolutely! You might have come across a phrase like JavaScript is a functional language or in JS, functions are first class objects. That means that the logic of properties and methods apply to functions, just as they do for any object (Arrays, Date, Object,...)
The main Function
hold the prototype that defines all basic properties and methods that all functions have. Rather than assigning new function objects to each function, it's just far more efficient to assign them to 1 object, to which all function objects points.
This means, like other have pointed out here:
function foo()
{};
foo.bind === Function.prototype.bind;
But this also means that you can augment both the prototype and the individual function objects:
Function.prototype.getName = function()
{
return this.name;
}
foo.getName();//foo
Again, here foo.getName === Function.prototype.getName
, but once we assign directly to a single function object:
foo.getName = function(){ return 'bar';};
It stands to reason that foo.getName !== Function.prototype.getName
... just play around with the Function prototype, and how it affects the behaviour of each function individually. It's good fun ;P