Socket
Socket
Sign inDemoInstall

get-prototype-chain

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-prototype-chain - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

5

get-prototype-chain.js
module.exports = function getPrototypeChain(obj) {
var chain = [];
var chain = [obj];
var prototype = obj;
while (prototype = Object.getPrototypeOf(prototype)) {
chain.push(prototype);
}
}
return chain;
};

2

package.json
{
"name": "get-prototype-chain",
"version": "1.0.0",
"version": "1.0.1",
"description": "Returns an array of the object's prototype chain",

@@ -5,0 +5,0 @@ "main": "get-prototype-chain.js",

@@ -33,3 +33,3 @@ # get-prototype-chain [![Build Status](https://travis-ci.org/leahciMic/get-prototype-chain.svg?branch=master)](https://travis-ci.org/leahciMic/get-prototype-chain)

// returns ['C', 'B', 'A', 'Object']
// returns ['C', 'C', 'B', 'A', 'Object']
```

@@ -6,17 +6,31 @@ 'use strict';

describe('prototype-chain', () => {
class A {
describe('complex hierarchy', () => {
class A {
}
class B extends A {
}
class B extends A {
}
class C extends B {
}
class C extends B {
}
const Obj = new C();
}
it('should walk the prototype chain and return objects', () => {
const chain = prototypeChain(Obj).map(x => x.constructor.name);
expect(chain).toEqual(['C', 'B', 'A', 'Object']);
const Obj = new C();
it('should walk the prototype chain and return objects', () => {
const chain = prototypeChain(Obj).map(x => x.constructor.name);
// we expect to see C twice, one for the instance, and one for it's
// prototype
expect(chain).toEqual(['C', 'C', 'B', 'A', 'Object']);
});
});
describe('simple object', () => {
const Obj = {};
it('should walk the prototype chain and return objects', () => {
const chain = prototypeChain(Obj).map(x => x.constructor.name);
expect(chain).toEqual(['Object', 'Object']);
});
});
});
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