我在 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/