0.1.1 • Published 6 years ago

@ganuz/find-prototype-of v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

@ganuz/find-prototype-of

Source Code Version MIT License Bundle Size TypeScript

Find Prototype Of is package from Ganuz library

Install

$ yarn add @ganuz/find-prototype-of

Or

$ npm install --save @ganuz/find-prototype-of

Use

Module

import {
  default as findPrototypeOf
} from '@ganuz/find-prototype-of';

Browser

<script src="https://unpkg.com/@ganuz/find-prototype-of/bundle.umd.min.js"></script>
let {
  findPrototypeOf
} = G;

Examples

 findPrototypeOf(null, proto => proto); // throw TypeError
 findPrototypeOf({}, proto => proto); // => null
 findPrototypeOf({foo: 'bar', [Symbol.toStringTag]: 'Foo'}, proto => proto.foo); // => Foo{foo: 'bar'}
 findPrototypeOf(function (){}, proto => proto.hasOwnProperty('hasOwnProperty')); // => Object.prototype
 let a = Object.create(null, {color: {value: 'red'}});
 let b = Object.create(a, {color: {value: 'blue'}});
 let c = Object.create(b, {color: {value: 'green'}});

 findPrototypeOf(c, (proto) => proto.color === 'blue') === b; // => true
 findPrototypeOf(c, (proto) => proto.color === 'pink'); // => null
 findPrototypeOf(c, (proto) => console.log(`color: ${proto.color}`));
 // => 'color: green'
 // => 'color: blue'
 // => 'color: red'
 // => null

License

Copyright © Yisrael Eliev, Licensed under the MIT license.