一堆同名的属性、变量,判断最终结果。
var number = 2;
var obj = {
number : 4,
fn1 : (function(){
this.number *= 2;
number = number * 2;
var number = 3;
return function(){
this.number *= 2;
number *= 3;
alert("inner:"+number);
}
})(),
fn2 : function(){
this.number *= 2;
}
};
//number 4
var fn1 = obj.fn1;
alert(number);
fn1();//number 8 "inner:"+number 9
alert(number)//number 8
obj.fn1();//obj.number 8 "inner:"+number 27
obj.fn2();//obj.number 16
alert(window.number);//8
alert(obj.number);//16
本文标题:一堆同名的属性、变量,判断最终结果。
本文链接:https://www.haomeiwen.com/subject/jywunftx.html
网友评论