Last active
October 7, 2015 12:12
-
-
Save NightOwlPrgmr/cec9a67b3a5516187ec4 to your computer and use it in GitHub Desktop.
JS Polyfill for IE Shortcomings
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
// IE7 fix for .forEach function | |
if (!Array.prototype.forEach) { | |
Array.prototype.forEach = function(fn, scope) { | |
for(var i = 0, len = this.length; i < len; ++i) { | |
fn.call(scope, this[i], i, this); | |
} | |
} | |
} | |
// IE7 & IE8 fix for .indexOf function | |
if (!Array.prototype.indexOf) { | |
Array.prototype.indexOf = function(elt /*, from*/) { | |
var len = this.length; | |
var from = Number(arguments[1]) || 0; | |
from = (from < 0) ? Math.ceil(from) : Math.floor(from); | |
if (from < 0) { from += len; } | |
for (; from < len; from++) { if (from in this && this[from] === elt) { return from; } } | |
return -1; | |
}; | |
} | |
// IE7 fix for counting keys in an object | |
if (!Object.keys) { | |
Object.keys = function(obj) { | |
var keys = [], k; | |
for (k in obj) { | |
if (Object.prototype.hasOwnProperty.call(obj, k)) { | |
keys.push(k); | |
} | |
} | |
return keys; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment