javascript - 这里打印的arguments为啥是null?
本文介绍了javascript - 这里打印的arguments为啥是null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
var a=3,b=4;function h(a,b){return a+b};console.dir(h)
function h(a.b)
arguments: null 这个为啥是null
caller: null
length: 2
name: "h"
prototype:Object
__proto__: function()
<function scope>
解决方案
function abc(x,y,z){ return arguments;};
console.dir(abc);
/*
abc(x, y, z)
arguments: null //没调用时没有
caller: null
length: 3 //如果要获取参数个数,应该用 length
name: "abc"
prototype: abc__proto__: ()<function scope>
*/
console.dir(abc(1,2,3));
/*
[1, 2, 3]
0: 1
1: 2
2: 3
callee: abc(x,y,z)
length: 3
*/
这篇关于javascript - 这里打印的arguments为啥是null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文