Skip to content

Instantly share code, notes, and snippets.

@schamane
Created June 3, 2011 12:21
Show Gist options
  • Save schamane/1006257 to your computer and use it in GitHub Desktop.
Save schamane/1006257 to your computer and use it in GitHub Desktop.
get function name from function self in oop
var C = function() {};
C.prototype.myFunctionName = function() {
var method, name;
for( method in this) {
if(!this.hasOwnProperty(method)){
if(this[method].toString() === arguments.callee.toString()){
name = method;
}
}
}
if(name)
console.log(method);
};
var c = new C();
c.myFunctionName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment