我有一个函数在 ExtJS 第 1433 行的某个地方中断。
var createDelayed = function(h, o, scope){
console.log(arguments); //logs undefined all round.
return function(){
var args = Array.prototype.slice.call(arguments, 0);
setTimeout(function(){
h.apply(scope, args);
}, o.delay || 10);
};
};
有什么方法可以查看函数是从哪一行执行的吗?
(因为它是第三方库,我真的不能这样做
var me =this;
and log me
)
有arguments.callee.caller
,它指的是调用您访问该属性的函数的函数。arguments.callee
是函数本身。
如果不传递原始函数,就无法获取它的作用域。在以下示例中,您无法确定this
里面的价值foo
(除了知道没有什么特别的事情发生this
here):
function foo() {
bar();
}
function bar() {
console.log(arguments.callee); // bar function
console.log(arguments.callee.caller); // foo function
}
foo();
文档
要获取行号,事情会变得更加棘手,但您可以抛出错误并查看堆栈跟踪:http://jsfiddle.net/pimvdb/6C47r/.
function foo() {
bar();
}
function bar() {
try { throw new Error; }
catch(e) {
console.log(e.stack);
}
}
foo();
对于 fiddle,它会在 Chrome 中记录类似于以下内容的内容,其中行尾表示行号和字符位置:
Error
at bar (http://fiddle.jshell.net/pimvdb/6C47r/show/:23:17)
at foo (http://fiddle.jshell.net/pimvdb/6C47r/show/:19:5)
at http://fiddle.jshell.net/pimvdb/6C47r/show/:29:1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)