-
-
Save muhamed-didovic/64f8634a1dd4ba466194 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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