JavaScript中this指针指向的彻底理解

this的指向在函数定义的时候是确定不了的,只有函数执行的时候才能确定this到底指向谁实际上this的最终指向的是那个调用它的对象

这一点与函数中*变量Action-varibal不同

      var object = {
name : 'The Kite Runner',
obj : {
name : 'childProperty',
fn : function(x, y){
var result = x + y;
console.log('this-context'+this);
console.log('this-property'+this.name);
console.log('result'+result);
}
}
} var f = object.obj.fn; //函数引用 f(); // this --window //修改this指向--object.obj对象
f.apply(object.obj, [10,25]);
f.call(object.obj, 25,45);

码农网 http://www.codeceo.com/article/javascript-this-pointer.html

一个程序员的自我修养 http://kb.cnblogs.com/page/545784/

上一篇:NSGA-II多目标优化算法讲解(附MATLAB代码)


下一篇:Hibernate(十六):Hibernate二级缓存