Created
October 9, 2013 14:35
-
-
Save dmgarland/6902298 to your computer and use it in GitHub Desktop.
Equals method in Javascript
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
| String.prototype.equals = function(s) { | |
| if(typeof(s) == "object") { | |
| return this.valueOf() === s.valueOf(); | |
| } | |
| else if(typeof(s) == "string") { | |
| return this.valueOf() === s; | |
| } | |
| else { | |
| return undefined; | |
| } | |
| }; | |
| console.log("123".equals("123")); | |
| console.log("123".equals(new String("123"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment