Possible Duplicate:
Javascript how do you find the caller function?
Is there a way to get the value of this
from the function which has called the current function?
Look at this:
function TraceMySelf(){
console.log(this);
}
function A(){
TraceMySelf();
console.log(this);
}
var a = new A();
When this code is executed, the console displays first the window
object and then the a
object. How can I make the code display the a
object twice, with only changing line 2? I know that I could apply the function inside A
with this
, but that isn't what I want.
Is this possible?