Skip to content
multiple inheritance using ES6 Proxy
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
setPrototypeOf.js
setPrototypeOf.min.js

README.md

Object.setPrototypesOf

multiple inheritance using Proxies

where

https://cdn.jsdelivr.net/npm/setprototypesof@1.0.1/setPrototypesOf.min.js

what

Set multiple [[Prototype]] linkages

Object.setPrototypesOf(target, prototype1, prototype2, ...);

how

const obj = {};

const baseObj1 = {prop: 'value'};
const baseObj2 = {prop2: 'value2'};
const baseObj3 = {prop3: 'value3'};

Object.setPrototypesOf(obj, baseObj1, baseObj2, baseObj3);

get

obj.prop; // 'value
obj.prop2; // 'value2
obj.prop3; // 'value3

set

obj.prop = 'new value';
obj.prop2 = 'new value2';
obj.prop3 = 'new value3';

obj; // {prop: 'new value', prop2: 'new value2', prop3: 'new value3'}

// WARNING
baseObj1.prop; // 'value'
baseObj2.prop2; // 'value2'
baseObj3.prop3; // 'value3'

getters

this into getters will point to obj if a getter was invoked by obj itself

aBaseObj; // {get foo() { return this.bar }, bar: 42}
obj; // {bar:'baz'}

obj.foo; // 'baz'

setters

this into setters will point to obj if a setter was invoked by obj itself

aBaseObj; // {set foo(value) { this.bar = value }, bar: 42}
obj; // {}

obj.foo = 'baz';
obj; // {bar: 'baz'}

// WARNING
aBaseObj; // {bar: 42}

invariants

  • target must be an object, a null value is not accepted
  • minimum number of required prototypes: 2 (otherwise use Object.setPrototypeOf)
  • all prototypes must be object, a null value is not accepted
You can’t perform that action at this time.