Last active
December 20, 2016 08:42
-
-
Save LukeChannings/5060084 to your computer and use it in GitHub Desktop.
prints the prototype chain for a constructed object.
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
/** | |
* prints the prototype chain for a constructed object. | |
* @param {Object} a constructed object. | |
* @param asArray {Boolean} if true, the chain will be returned as an array. | |
*/ | |
function printPrototypeChain(instance, asArray) { | |
var chain = [] | |
while (instance = Object.getPrototypeOf(instance)) { | |
var name = instance.constructor.toString().match(/f.+n (.+)\(/) | |
chain.push(name && name[1]? name[1] : "(anonymous function expression)") | |
} | |
return asArray? chain : chain.join(" -> ") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: