This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const metaHandler = { | |
get: function (dt, trapName) { | |
console.log(dt, trapName); | |
return Reflect[trapName]; | |
} | |
}; | |
const dummyTarget = {}; | |
const baseHandler = new Proxy(dummyTarget, metaHandler); | |
const target = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var target = { id : "boo" }; | |
var p = new Proxy(target, { | |
get: function(target, property, receiver) { | |
}, | |
set: function(target, property, value, receiver) { | |
}, | |
defineProperty: function(target, property, propDesc) { | |
}, | |
deleteProperty: function(target, property) { | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const proxy = new Proxy( | |
{ id: "id-0" }, | |
{ | |
set: function (target, property, value, receiver) { | |
if (property.charAt(0) === "_") return false; | |
target[property] = value; | |
return true; | |
} | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var target = { id: "id-0" }; | |
var handler = { | |
set: function (target, property, value, receiver) { | |
if (property.charAt(0) === "_") return false; | |
target[property] = value; | |
return true; | |
} | |
}; | |
var proxy = new Proxy(target, handler); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const foo = (a, b, c) => `${a}:${b}:${c}`; | |
const proxy = new Proxy(foo, { | |
apply: function(target, thisArg, argumentsList) { | |
return target.apply(thisArg, argumentsList); | |
} | |
}); | |
console.log(proxy("1", "2", "3")); // 1:2:3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
constructor (value) { this.value = value; } | |
getValue() { return this.value; } | |
} | |
const proxiedClass = new Proxy(A, { | |
construct: function(target, [ first ], newTarget) { | |
return new target(first + ":proxy-value"); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handler = { | |
get: function(target, property, receiver) { | |
if (property.startAt(0) === "_") return undefined; | |
return target[property]; | |
} | |
}; | |
const proxy = new Proxy({}, handler); | |
console.log(proxy.id); // 'ABCD' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handler = { | |
defineProperty: function(target, property, descriptor) { | |
if (property.charAt(0) === "_") return false; | |
return Reflect.defineProperty(target, property, descriptor); | |
} | |
}; | |
const proxy = new Proxy({}, handler); | |
proxy.id = "ABCD"; // { id: 'ABCD' } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var proxiedObject = new Proxy(target, handler); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var weaver = function (target, methodName) { | |
var before = function () { | |
console.log(arguments); | |
}; | |
var old = target[methodName]; | |
target[methodName] = function () { | |
before.apply(this, arguments); | |
return old.apply(this, arguments); | |
}; |