-1

谁能告诉我返回什么索引?我很确定它是0。

function jsTest() {

    var index = 0;
    var counter = 0;
    var obj = {};

    obj.index = index;

    var func = function () {
        for (index = 0; index < 10; index++) {
            counter += 2;
        }
        obj.index++;    
    };

    obj.func = func;
    this.index++;

    return index;

}
4

2 回答 2

3

It should be 0. Since the only place that can change local variable index is in function func, but it doesn't get called. Note that this.index is different from local variable index. BTW, this.index++ makes no sense since this.index is undefined).

于 2013-01-25T05:42:13.847 回答
2

Zero. At least that's what Chrome gave. Also obvious when you see that nothing changes it.

于 2013-01-25T05:40:45.217 回答