//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com //*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt //*** Reuse or modification is free provided you abide by the terms of that license. //*** (Including the first two lines above in your source code satisfies the conditions.) // Extends function objects to have a method to return their own name. Function.prototype.getName=function(){ var str = this.toString(); return str.substr(9,str.indexOf('(')-9); } //e.g. //function foo(){ bar() } //function bar(){ alert("I was called by "+bar.caller.getName()) }