Skip to content

Instantly share code, notes, and snippets.

@muhamed-didovic
Forked from mathiasverraes/getclass.js
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save muhamed-didovic/64f8634a1dd4ba466194 to your computer and use it in GitHub Desktop.

Select an option

Save muhamed-didovic/64f8634a1dd4ba466194 to your computer and use it in GitHub Desktop.
var getClass = function() {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
// define a class
function Animal() {}
// do this for all classes that need the getClass() method
Animal.prototype.getClass = getClass;
myDog = new Animal();
assert(myDog.getClass() == 'Animal');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment