Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // call cloner with base and a list of items to clone (same type preferably) of the same type
- function cloner(base, clones){
- var handler = {
- get(target, name, reciever){
- if (typeof target[name] == "function"){
- // call the function with args to all contexts
- return function (...args){
- clones.forEach((x) => x[name].apply(this, args));
- // return whatever base returns
- return target[name].apply(this, args)
- }
- } else {
- // just return base context value if it's not a function
- return target[name];
- }
- },
- set(obj, prop, val) {
- clones.forEach((x) => x[prop] = val);
- obj[prop] = val;
- return val;
- }
- }
- return new Proxy(base, handler);
- }
Add Comment
Please, Sign In to add comment