Samuel Burbano
Coding is easy, logically coding is what makes it special.
// Samuel Burbano
const socials = {
twitter: "@iosamuel",
facebook: "iosamuel.dev",
github: "iosamuel",
web: "iosamuel.dev"
};
const handler = {
set: function(target, prop, value, receiver) {
const val = value ? value : "invalid";
return Reflect.set(target, prop, val, receiver);
},
get: function(target, name) {
return name in target
? target[name]
: 37;
}
};
const p = new Proxy({}, handler);
p.a = 1;
p.b = undefined;
console.log(p.a, p.b); // 1, "invalid"
console.log('c' in p, p.c); // false, 37
const target = {};
/*
{
value: 37,
writable: true,
enumerable: true,
configurable: true
}
*/
Object.defineProperty(target, "c", {
enumerable: true,
configurable: true,
get() {
return !this.value ? 'no definido' : this.value;
},
set(val) {
this.value = val;
}
});
deleteProperty()
construct()
apply()
has()
Target
Handler
Object {}
Function ()
Array []
Proxy
has()
deleteProperty()
get()
set()
apply()
etc
const target = {}; // Objeto donde aplicar las trampas
const handler = {}; // Set de trampas
const p = new Proxy(target, handler);
// Samuel Burbano
const socials = {
twitter: "@iosamuel",
facebook: "iosamuel.dev",
github: "iosamuel",
web: "iosamuel.dev"
};
By Samuel Burbano