Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
setPrototypesOf helper es2015
var obj3 = {
baz: 3
}
var obj2 = {
bar: 2
}
var obj1 = {
foo: 1
};
var setPrototypesOf = function setPrototypesOf (trg, ...rest) {
var handlers = {
get(target, key, context) {
if (Reflect.has(target, key)) {
return Reflect.get(target, key, context);
} else {
for (let P of target[Symbol.for('[[Prototype]]')]) {
if (Reflect.has(P, key, context)) {
return Reflect.get(P, key, context);
}
}
}
}
};
trg[Symbol.for('[[Prototype]]')] = rest;
return new Proxy(trg, handlers);
};
var proxy = setPrototypesOf(obj1, obj2, obj3);
console.log(proxy.foo);
console.log(proxy.bar);
console.log(proxy.baz);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.