@ganuz/each-prototype-of
v0.1.1
Published
Each Prototype Of is package from Ganuz library
Downloads
17
Maintainers
Readme
@ganuz/each-prototype-of
Each Prototype Of is package from Ganuz library
Install
$ yarn add @ganuz/each-prototype-of
Or
$ npm install --save @ganuz/each-prototype-of
Use
Module
import {
default as eachPrototypeOf
} from '@ganuz/each-prototype-of';
Browser
<script src="https://unpkg.com/@ganuz/each-prototype-of/bundle.umd.min.js"></script>
let {
eachPrototypeOf
} = G;
Examples
eachPrototypeOf(null, p => p); // throw TypeError
eachPrototypeOf({[Symbol.toStringTag]: 'Some'}, p => p); // => Some{}
eachPrototypeOf(class A{}, p => p); // => class A{}
let a = Object.create(null, {name: {value: 'bob'}});
let b = Object.create(a, {name: {value: 'alice'}});
let c = Object.create(b, {name: {value: 'john'}});
let d = Object.create(c, {name: {value: 'alice'}});
let getProtoByName = (target, name) => (eachPrototypeOf(target, proto => !(proto.name === name && target = proto), target);
getProtoByName(d, 'alice'); // => d
getProtoByName(c, 'alice'); // => b
getProtoByName(a, 'alice'); // => null
getProtoByName(d, 'leonard'); // => null
eachPrototypeOf(c, console.log.bind(null, 'proto:'));
// => 'proto: c'
// => 'proto: b'
// => 'proto: a'
// => c
License
Copyright © Yisrael Eliev, Licensed under the MIT license.