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" );
@H_
403_4@对Jeffery下面的
代码的微小
修改帮助我了解内部匿名
函数中使用的参数.我刚才改了3行
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");
@H_
403_4@感谢大家