function main()
{
Hello();
}
function Hello()
{
// How do you find out the caller function is 'main'?
}
Run Code Online (Sandbox Code Playgroud)
有没有办法找出调用堆栈?
如何从该函数内部访问函数名?
// parasitic inheritance
var ns.parent.child = function() {
var parent = new ns.parent();
parent.newFunc = function() {
}
return parent;
}
var ns.parent = function() {
// at this point, i want to know who the child is that called the parent
// ie
}
var obj = new ns.parent.child();
Run Code Online (Sandbox Code Playgroud) 是否有可能做到这一点:
myfile.js:
function foo() {
alert(<my-function-name>);
// pops-up "foo"
// or even better: "myfile.js : foo"
}
Run Code Online (Sandbox Code Playgroud)
我的堆栈中有Dojo和jQuery框架,所以如果其中任何一个更容易,它们就可用了.