1 /** @scope Object
  2   Polyfill for Object.keys().
  3 
  4   Supports using `Object.keys()` on browsers prior to the following:
  5 
  6   * Chrome 5
  7   * Firefox 4.0 (Gecko 2.0)
  8   * Internet Explorer 9
  9   * Opera 12
 10   * Safari 5
 11 */
 12 // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
 13 if (!Object.keys) {
 14   Object.keys = (function() {
 15     var hasOwnProperty = Object.prototype.hasOwnProperty,
 16         hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
 17         dontEnums = [
 18           'toString',
 19           'toLocaleString',
 20           'valueOf',
 21           'hasOwnProperty',
 22           'isPrototypeOf',
 23           'propertyIsEnumerable',
 24           'constructor'
 25         ],
 26         dontEnumsLength = dontEnums.length;
 27 
 28     return function(obj) {
 29       if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
 30         throw new TypeError('Object.keys called on non-object');
 31       }
 32 
 33       var result = [], prop, i;
 34 
 35       for (prop in obj) {
 36         if (hasOwnProperty.call(obj, prop)) {
 37           result.push(prop);
 38         }
 39       }
 40 
 41       if (hasDontEnumBug) {
 42         for (i = 0; i < dontEnumsLength; i++) {
 43           if (hasOwnProperty.call(obj, dontEnums[i])) {
 44             result.push(dontEnums[i]);
 45           }
 46         }
 47       }
 48       return result;
 49     };
 50   }());
 51 }
 52