Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Created December 10, 2019 03:52
Show Gist options
  • Save jasondmoss/59d2335b6b2b5be2e480331662bdcbd7 to your computer and use it in GitHub Desktop.
Save jasondmoss/59d2335b6b2b5be2e480331662bdcbd7 to your computer and use it in GitHub Desktop.
Polyfill Methods for Internet Explorer 11 and below.
/**
* Polyfill for `String.prototype.startsWith()`
*
* @return {Boolean}
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
*/
if (!String.prototype.startsWith) {
Object.defineProperty(String.prototype, "startsWith", {
value: function (search, pos) {
"use strict";
pos = !pos || pos < 0 ? 0 : +pos;
return this.substring(pos, pos + search.length) === search;
}
});
}
/* <> */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment