Socket
Socket
Sign inDemoInstall

protochain

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    protochain

Get the prototype chain of any value as an Array


Version published
Weekly downloads
47K
decreased by-3.73%
Maintainers
1
Install size
11.9 kB
Created
Weekly downloads
 

Readme

Source

protochain

Build Status

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({})
// => [Object.prototype]

protochain(Object.create(null))
// => []

protochain(new Error('message'))
// => [Error.prototype, Object.prototype]

protochain(new TypeError('message'))
// => [TypeError.prototype, Error.prototype, Object.prototype]

// Inheritance

function Person() {

}

function FancyPerson() {
  Person.call(this)
}

FancyPerson.prototype = Object.create(Person.prototype)

protochain(new Person())
// => [Person.prototype, Object.prototype]

protochain(new FancyPerson())
// => [FancyPerson.prototype, Person.prototype, Object.prototype]

// Primitives are OK

protochain(123)
// => [Number.prototype, Object.prototype]

protochain('abc')
// => [String.prototype, Object.prototype]

protochain(/abc/)
// => [RegExp.prototype, Object.prototype]

protochain(true)
// => [Boolean.prototype, Object.prototype]

protochain(false)
// => [Boolean.prototype, Object.prototype]

// Null & Undefined === Empty List

protochain(null)
// => []

protochain(undefined)
// => []

protochain()
// => []

ES6


import protochain from 'protochain'

class Person {}
class FancyPerson extends Person {}

protochain(new Person())
// => [Person.prototype, Object.prototype]

protochain(new FancyPerson())
// => [FancyPerson.prototype, Person.prototype, Object.prototype])

License

MIT

Keywords

FAQs

Last updated on 30 Jun 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc