protochain
Get the prototype chain of an object or primitive as an Array.
Why
I often write this function, figure I should extract it. There are
probably other utilities out there that do this but I couldn't find
them so they're either poorly named/described or the search algorithm is not being very helpful or I simply searched for the wrong things.
Installation
> npm install protochain
Usage
ES5
var protochain = require('protochain')
protochain({})
protochain(Object.create(null))
protochain(new Error('message'))
protochain(new TypeError('message'))
function Person() {
}
function FancyPerson() {
Person.call(this)
}
FancyPerson.prototype = Object.create(Person.prototype)
protochain(new Person())
protochain(new FancyPerson())
protochain(123)
protochain('abc')
protochain(/abc/)
protochain(true)
protochain(false)
protochain(null)
protochain(undefined)
protochain()
ES6
import protochain from 'protochain'
class Person {}
class FancyPerson extends Person {}
protochain(new Person())
protochain(new FancyPerson())
License
MIT