关于arguments的使用
来源:16-1 作用域和闭包-执行上下文
美乐居士
2019-09-09
var length = 10;
function fn() {
console.log(this.length);
}
var obj = {
method: function(fn) {
fn();
arguments[0]();
}
};
obj.method(fn, 1);

输出:10,2
请问老师,这里的2是怎么取得输出的
写回答
2回答
-
var length = 10;
function fn() {
console.log(this.length);
}
var obj = {
method: function(fn) {
console.log('arguments[0]...', arguments[0])
console.log('arguments.length...', arguments.length)
arguments[0](); // 执行函数会打印 this.length ,值即上一行的 arguments.length
}
};
obj.method(fn, 1);
看我加的两行 console.log 和一行注释吧,应该就能明白了。
012019-09-10 -
双越
2019-09-09
“arguments0;”—— 这里是不是写错了?我是不太理解这种写法
你先把代码格式化一下吧,参考 http://coding.imooc.com/learn/questiondetail/141504.html 这种格式化形式
032019-09-10
相似问题