Last active
December 10, 2019 03:52
-
-
Save jasondmoss/9ac52db0a27bfa5695a8cd532759b5ad to your computer and use it in GitHub Desktop.
Polyfill Methods for Internet Explorer 11 and below.
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
/** | |
* Polyfill for `String.prototype.includes()` | |
* | |
* @param {String} String to search for. | |
* @param {Integer} Start search at 'this' position. | |
* | |
* @return {Boolean} | |
* | |
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes | |
*/ | |
if (!String.prototype.includes) { | |
String.prototype.includes = function (search, start) { | |
"use strict"; | |
if (!exists(search)) { | |
return false; | |
} | |
if (typeof start !== "number") { | |
start = 0; | |
} | |
if (start + search.length > this.length) { | |
return false; | |
} | |
return this.indexOf(search, start) !== -1; | |
}; | |
} | |
/* <> */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment