Skip to content

Instantly share code, notes, and snippets.

@cms
Created October 19, 2010 07:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cms/633782 to your computer and use it in GitHub Desktop.
Save cms/633782 to your computer and use it in GitHub Desktop.
ES6 Object.getPropertyNames
Object.getPropertyNames ||
Object.defineProperty(Object, "getPropertyNames", {
value: function(obj) {
var propertyNames = [];
do {
propertyNames.push.apply(propertyNames, Object.getOwnPropertyNames(obj));
obj = Object.getPrototypeOf(obj);
} while (obj);
// get unique property names
obj = {};
for(var i = 0, len = propertyNames.length; i < len; i++) {
obj[propertyNames[i]] = 1;
}
return Object.keys(obj);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment