Getting the name of current function in javascript
by mwagner72
JavaScript
function thisWorksLikeThis(){
var functionName = arguments.callee.name; // this is dynamic
console.log("inside the function " + functionName)
}
function myLogger(obj, callee, text) {
var text = text || '';
for(var propt in obj){
if(obj[propt] === callee) {
console.log(propt + ": " + text, obj);
}
}
}
Foo = function(){
this.some_property = "some value";
}
Foo.prototype.bar = function(){
myLogger(this, arguments.callee, "initial state");
this.some_property = 'another value';
myLogger(this, arguments.callee, "ending state");
}
thisWorksLikeThis();
foo = new Foo();
foo.bar();