Last active
August 29, 2015 14:06
-
-
Save st98/3725b6571928bc072a3a to your computer and use it in GitHub Desktop.
Array#has。
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.defineProperty(Array.prototype, 'has', { | |
value: function (value) { | |
return this.indexOf(value) > -1; | |
}, | |
enumerable: false, | |
configurable: true, | |
writable: false | |
}); | |
Object.defineProperty(Array.prototype, 'contains', | |
Object.getOwnPropertyDescriptor(Array.prototype, 'has') | |
); | |
//----- | |
[1, 2, 3].has(2); // => true | |
[1, 2, 3].has(4); // => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment