Created
October 6, 2011 21:13
-
-
Save dkordik/1268693 to your computer and use it in GitHub Desktop.
Ruby's .class for Javascript... kinda
This file contains 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
Object.prototype.class = function () { | |
var match = this.constructor.toString().match("function " + /([A-Za-z]+)/.source) || this.constructor.toString().match("return new " + /([A-Za-z]+)/.source); | |
return match[1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment