call this的范围

var f1=function(){this.a="类f1的实例的a属性"};

f1代表一个类;

f1.a='对象f1的a属性';

var f2=function(){};//类f2的实例没有a属性

f2.a='对象f2的a属性';

var test=function(){alert(this.a)};

test.call(f1);//弹出‘对象f1的a属性’

test.call(new f1());//弹出“类f1的实例的a属性”

test.call(f2);//弹出“对象f2的a属性”

test.call(new f2());//弹出undefined

posted on 2014-01-10 16:23  学无止境2023  阅读(145)  评论(0编辑  收藏  举报

导航