gpt4 book ai didi

javascript - 如何在 JavaScript 中找到调用函数?

转载 作者:可可西里 更新时间:2023-11-01 02:15:02 26 4
gpt4 key购买 nike

我在 JS 中有一个函数被从多个地方调用..

现在我正在 iPad 上测试这个页面,因此发现调试有点困难。

我可以通过某种方式(在控制台上打印)找出我的函数是从哪里调用的吗?

最佳答案

像这样?

function testOne() {
console.log("Test 1");
logTest();
}
function testTwo() {
console.log("Test 2");
logTest();
}
function logTest() {
console.log("Being called from " + arguments.callee.caller.toString());
}

testOne();
testTwo();

如果你在你的 JavaScript 文件中使用 'use strict';,你需要注释/删除它,否则你会得到这样的东西:

Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them

关于javascript - 如何在 JavaScript 中找到调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8211264/

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