Skip to content

Instantly share code, notes, and snippets.

@phaberest
Created January 18, 2019 17:36
Show Gist options
  • Select an option

  • Save phaberest/85f5a48b731d605f7da2db7b444ae984 to your computer and use it in GitHub Desktop.

Select an option

Save phaberest/85f5a48b731d605f7da2db7b444ae984 to your computer and use it in GitHub Desktop.

Revisions

  1. phaberest created this gist Jan 18, 2019.
    28 changes: 28 additions & 0 deletions ie_includes_polyfill.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // includes() polyfill for strings
    if (!String.prototype.includes) {
    String.prototype.includes = function(search, start) {
    'use strict';
    if (typeof start !== 'number') {
    start = 0;
    }

    if (start + search.length > this.length) {
    return false;
    } else {
    return this.indexOf(search, start) !== -1;
    }
    };
    }

    // includes() polyfill for arrays
    if (!Array.prototype.includes) {
    Object.defineProperty(Array.prototype, "includes", {
    enumerable: false,
    value: function(obj) {
    var newArr = this.filter(function(el) {
    return el == obj;
    });
    return newArr.length > 0;
    }
    });
    }