Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments),
object = args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)));
};
};
var myObject = {};
function myFunction(){
return this == myObject;
}
assert( !myFunction(), "Context is not set yet" );
var aFunction = myFunction.bind(myObject)
assert( aFunction(), "Context is set properly" );
Tiny modification to Jeffery's code below helped me understand the arguments used in the inner anonymous function. I just changed the 3 lines below
var introduce = function(greeting) { alert(greeting + ", my name is " + this.name + " ,home no is " + arguments[1]); }
hiBob(" 456"); // alerts "Hi, my name is Bob"
yoJoe(" 876");
Thanks everyone