Created
October 19, 2010 07:35
-
-
Save cms/633782 to your computer and use it in GitHub Desktop.
ES6 Object.getPropertyNames
This file contains 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.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