Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protochain

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protochain

Prototype chain of any value as an Array

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53K
decreased by-28.59%
Maintainers
1
Weekly downloads
 
Created
Source

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({})
// => [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

Package last updated on 06 Mar 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc