日期:2014-05-16  浏览次数:20303 次

obj.method()函数里的this,应该是指?
function arrTest() {
var arr = [];
arr["a"] = 123;
arr.method1 = function () {
console.log(this["a"]);
};

for (var p in arr) {
console.log(p+":"+arr[p]);
}

arr.method1();//这里是啥?你们绝对想不到
}


arr.method1()的运行结果令我大吃一惊,你们能想到是什么吗?
------解决方案--------------------
很正常啊,返回123,
你是把

arr.method1 = function () {
        console.log(this["a"]);
    };

当成this了吧,这个是上面那个for循环的结果.