gpt4 book ai didi

javascript - Function.caller.arguments 和 Function.arguments 之间有什么区别?

转载 作者:行者123 更新时间:2023-11-28 14:57:12 24 4
gpt4 key购买 nike

我在函数foo中使用foo.caller.arguments还是简单的arguments有什么区别:

function foo(){
console.log(foo.caller.arguments);
}

function foo(){
console.log(arguments);
}

最佳答案

正如问题评论中所述,caller 不是标准属性: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller

话虽如此,它返回调用者的引用,即调用当前函数的函数。因此,caller.arguments 可以获取调用者被调用的参数。

arguments 获取当前函数调用中使用的参数。

例如:

function one(c) {
console.log('arguments', arguments);
console.log('caller.arguments', one.caller.arguments);
}

function two(a, b) {
one(3);
}

two(1, 2)

打印

arguments [3]
caller.arguments [1, 2]

关于javascript - Function.caller.arguments 和 Function.arguments 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42438216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com