/ Published in: JavaScript
Get Function Name
============
This will only return (a string) if the object passed to getFunctionName is a function or an "object" function from IE.
The function does not rely on function.name if present as it can't always be trusted.
Examples:
getFunctionName(function Foo(){}) == "Foo"
getFunctionName(function(){}) == ""
============
This will only return (a string) if the object passed to getFunctionName is a function or an "object" function from IE.
The function does not rely on function.name if present as it can't always be trusted.
Examples:
getFunctionName(function Foo(){}) == "Foo"
getFunctionName(function(){}) == ""
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getFunctionName(func) { if ( typeof func == "function" || typeof func == "object" ) var fName = (""+func).match( /function\s*([\w\$]*)\s*\(/ ); if ( fName !== null ) return fName[1]; }