这里打印的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>
阅读 4k
5 个回答
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
*/
var a=3,b=4;function h(a,b){return a+b};console.dir(h)

你打印的是h 不是 h()
h 是函数的引用
h()是执行函数
另外h()执行也要传参数,不传参数就是undefined

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题