UNPKG

raptor-polyfill

Version:

Polyfills for various EcmaScript 5 and EcmaScript 6 methods distributed as CommonJS modules that can be require'd individually or as a whole.

48 lines (41 loc) 1.35 kB
// ES5 15.2.3.14 // http://es5.github.com/#x15.2.3.14 if (!Object.keys) { var _hasOwnProperty = Object.prototype.hasOwnProperty; // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation var hasDontEnumBug = true, dontEnums = [ "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor" ], dontEnumsLength = dontEnums.length; /*jshint unused:false*/ for (var key in {"toString": null}) { hasDontEnumBug = false; } Object.keys = function keys(object) { if ((typeof object != "object" && typeof object != "function") || object === null) { throw new TypeError("Object.keys called on a non-object"); } var _keys = []; for (var name in object) { if (_hasOwnProperty.call(object, name)) { _keys.push(name); } } if (hasDontEnumBug) { for (var i = 0, ii = dontEnumsLength; i < ii; i++) { var dontEnum = dontEnums[i]; if (_hasOwnProperty.call(object, dontEnum)) { _keys.push(dontEnum); } } } return _keys; }; }