Created
March 29, 2019 02:56
-
-
Save lambdaydoty/6a7afd6b3d02dcf7f6d6b68320f7059d to your computer and use it in GitHub Desktop.
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
const trace = require('./javascript-trace-prototype-chain') | |
class Animal {} | |
class Dog extends Animal {} | |
class Bichon extends Dog {} | |
class Foo extends Bichon {} | |
const foo = new Foo() | |
console.log(trace(foo)) | |
console.log(trace('abc')) | |
console.log(trace(() => {})) | |
console.log(trace([])) | |
console.log(trace({})) |
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
module.exports = trace | |
function trace (object) { | |
let proto = object.constructor.prototype | |
let result = '*' | |
while (proto) { | |
result += ` -> ` + proto.constructor.name | |
proto = Object.getPrototypeOf(proto) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment