Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Created July 19, 2014 15:59
Show Gist options
  • Save raineorshine/cbe3b4be2bae9aeba9b3 to your computer and use it in GitHub Desktop.
Save raineorshine/cbe3b4be2bae9aeba9b3 to your computer and use it in GitHub Desktop.
Get the name of an object's constructor as a string. As described here: http://stackoverflow.com/questions/332422/how-do-i-get-the-name-of-an-objects-type-in-javascript/332429#332429
Object.prototype.getName = function() {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment