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

标签 javascript firebug dom-events

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

相关文章:

javascript - jquery ajax : headers seem to not be working

javascript - window.location 改变时中断?

javascript - 是否可以使用 Firebug 分析内置 JavaScript 函数?

html - 处理按钮双击的默认行为

javascript - 函数到达末尾后如何再次运行它?

javascript - 将来自 jquery 选择器的值存储在数组或哈希中以供重用

javascript - 如何在 Backbone 中使用 setTimeout()?

java - 在 eclipse Mars IDE 上通过 selenium webdriver 启动 Firefox 时,Firebug 不显示。

javascript - 如何检查 Chrome Dev Tools 是否打开?

javascript - 不需要的递归 - 如何避免子级单击事件传递给 jquery 中的父级?