Last active
August 29, 2015 14:16
-
-
Save maxgherman/329b583a4db00ef5f736 to your computer and use it in GitHub Desktop.
Retrieve all property names for JavaScript object including non enumerables
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
function getAllPropertyNames(obj) { | |
var props = {}; | |
do { | |
Object.getOwnPropertyNames(obj).forEach(function (prop) { | |
if (prop !== 'constructor') { | |
props[prop] = undefined; | |
} | |
}); | |
} while ((obj = Object.getPrototypeOf(obj)) !== Object.prototype); | |
return Object.getOwnPropertyNames(props); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment