Last active
August 29, 2015 14:16
-
-
Save foomin10/8609bf3a48d641455c5b to your computer and use it in GitHub Desktop.
[JavaScript] String#contains で正規表現マッチができればいいのに ref: http://qiita.com/MizuiroFolder/items/8dcf74a404d5dcf70fe8
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
'foo'.contains('o'); //=> true | |
'foo'.contains(/o/); //=> true |
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
(function(){ | |
let _contains = String.prototype.contains; | |
Object.defineProperty(String.prototype, 'contains', { | |
enumerable: false, | |
configurable: true, | |
writable: true, | |
value: function contains(...args){ | |
let [searchString, position] = args; | |
if(searchString != undefined && searchString.constructor === RegExp){ | |
return searchString.test(this.slice(position)); | |
}else{ | |
return _contains.call(this, ...args); | |
} | |
}, | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment