gpt4 book ai didi

google-apps-script - 如何获取arguments.callee.caller?

转载 作者:行者123 更新时间:2023-12-01 11:46:42 26 4
gpt4 key购买 nike

我试图通过使用 arguments.callee.caller 找出调用我的 Google Apps 脚本函数的函数的名称。如 How do you find out the caller function in JavaScript? ,但似乎没有导出这样的属性。 (但是,arguments.callee 存在。)

如何在 Google Apps 脚本中获取该调用函数的名称?

作为次要问题,为什么不是 arguments.callee.caller那里?

最佳答案

我做了这个功能:

function getCaller()
{
var stack;
var ret = "";
try
{
throw new Error("Whoops!");
}
catch (e)
{
stack = e.stack;
}
finally
{
var matchArr = stack.match(/\(.*\)/g);
if (matchArr.length > 2)
{
tmp = matchArr[2];
ret = tmp.slice(1, tmp.length - 1) + "()";
}
return ret;
}
}

它作为 Error() 抛出,然后从堆栈跟踪中获取函数名称。
尝试在使用包装器时改变 matchArr[2] 中的“2”。

关于google-apps-script - 如何获取arguments.callee.caller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713292/

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