Skip to content

Commit

Permalink
IE Bug Fix: Add includes polyfill (prebid#464)
Browse files Browse the repository at this point in the history
* Add includes polyfill

* switch includes polyfill to use Object.defineProperty
  • Loading branch information
ehoch authored and jaiminpanchal27 committed Aug 2, 2016
1 parent 85bc36d commit 45fd284
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,34 @@ if (!Array.prototype.find) {
return undefined;
}
});
}
}

if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, "includes", {
value: function(searchElement) {
var O = Object(this);
var len = parseInt(O.length, 10) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1], 10) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {k = 0;}
}
var currentElement;
while (k < len) {
currentElement = O[k];
if (searchElement === currentElement ||
(searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN
return true;
}
k++;
}
return false;
}
});
}

0 comments on commit 45fd284

Please sign in to comment.