Created
August 19, 2013 12:07
-
-
Save pwartbichler/6268424 to your computer and use it in GitHub Desktop.
Object.keys does not exist in IE8. This is a workaround.
This file contains hidden or 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
Object.keys = Object.keys || (function () { | |
var hasOwnProperty = Object.prototype.hasOwnProperty, | |
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"), | |
DontEnums = [ | |
'toString', | |
'toLocaleString', | |
'valueOf', | |
'hasOwnProperty', | |
'isPrototypeOf', | |
'propertyIsEnumerable', | |
'constructor' | |
], | |
DontEnumsLength = DontEnums.length; | |
return function (o) { | |
if (typeof o != "object" && typeof o != "function" || o === null) | |
throw new TypeError("Object.keys called on a non-object"); | |
var result = []; | |
for (var name in o) { | |
if (hasOwnProperty.call(o, name)) | |
result.push(name); | |
} | |
if (hasDontEnumBug) { | |
for (var i = 0; i < DontEnumsLength; i++) { | |
if (hasOwnProperty.call(o, DontEnums[i])) | |
result.push(DontEnums[i]); | |
} | |
} | |
return result; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment