There is no such reflection functionality. A function doesn't know itself other than by explicit reference (arguments.callee
is deprecated), and function objects are not bound to any properties anyway so they cannot know the respective property name. Whenever you need a "method name", hardcode it as a string literal.
OK, there is something you could do (using a named function expression, you can change it to a function declaration for IE):
Constr.prototype.someProperty = function myFuncName(args…) {
var propertyName = "";
for (var p in this)
if (this[p] == myFuncName) {
propertyName = p;
break;
}
alert("this function (myFuncName) was found on property '"
+propertyName+"' of `this` object");
};
var inst = new Constr(…);
inst.someProperty(…); // alerts "… found on property 'someProperty' …"
However, this is an ugly hack and you should not use it.