Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lambdaydoty/6a7afd6b3d02dcf7f6d6b68320f7059d to your computer and use it in GitHub Desktop.
Save lambdaydoty/6a7afd6b3d02dcf7f6d6b68320f7059d to your computer and use it in GitHub Desktop.
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({}))
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