Get Function Name


/ Published in: JavaScript
Save to your folder(s)

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(){}) == ""


Copy this code and paste it in your HTML
  1. function getFunctionName(func) {
  2. if ( typeof func == "function" || typeof func == "object" )
  3. var fName = (""+func).match(
  4. /function\s*([\w\$]*)\s*\(/
  5. ); if ( fName !== null ) return fName[1];
  6. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.