Skip to content

Commit

Permalink
shims for IE8
Browse files Browse the repository at this point in the history
  • Loading branch information
warpech committed Nov 3, 2014
1 parent 54f5081 commit 5e8fd0c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ module.exports = function (grunt) {
shims: [
'lib/shims/array.indexOf.js',
'lib/shims/array.filter.js',
'lib/shims/array.isArray.js',
'lib/shims/object.keys.js',
'lib/shims/weakmap.js'
]
},
Expand Down
5 changes: 5 additions & 0 deletions lib/shims/array.isArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
42 changes: 42 additions & 0 deletions lib/shims/object.keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
// License CC-BY-SA v2.5
if (!Object.keys) {
Object.keys = (function() {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;

return function(obj) {
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}

var result = [], prop, i;

for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}

if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
}

0 comments on commit 5e8fd0c

Please sign in to comment.