Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  70] [ 4]  / answers: 1 / hits: 17324  / 13 Years ago, fri, september 16, 2011, 12:00:00

I have a function that breaks somewhere in Line 1433 of ExtJS.



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);
};
};


Is there any way to see what line a function is executed from, from within itself?



(since it's a third party lib, and I cant really do



var me =this;


and log me)


More From » extjs

 Answers
5

There is arguments.callee.caller, which refers to the function that called the function in which you access that property. arguments.callee is the function itself.



There is no way to get the scope of the original function without passing it. In the following example, you cannot determine the this value inside foo (apart from knowing there is nothing special happening with this here):



function foo() {
bar();
}

function bar() {
console.log(arguments.callee); // bar function
console.log(arguments.callee.caller); // foo function
}

foo();


Documentation






To get the line number things becomes trickier, but you can throw an error and look at the stack trace: http://jsfiddle.net/pimvdb/6C47r/.



function foo() {
bar();
}

function bar() {
try { throw new Error; }
catch(e) {
console.log(e.stack);
}
}

foo();


For the fiddle, it logs something similar to the following in Chrome, where the end of the line says the line number and character position:



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

[#90065] Thursday, September 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
masonm

Total Points: 167
Total Questions: 87
Total Answers: 103

Location: Rwanda
Member since Wed, Jun 8, 2022
2 Years ago
masonm questions
;