Very simple proxy using the set trap

suggest change

This proxy appends the string " went through proxy" to every string property set on the target object. A value that is not a string is not stored. The trap returns undefined, so the assignment throws TypeError in strict mode after the string has been written.

let object  = {};

let handler = {
    set(target, prop, value){ // Note that ES6 object syntax is used
        if('string' === typeof value){
            target[prop] = value + " went through proxy";
        }
    }
};

let proxied = new Proxy(object, handler);

proxied.example = "ExampleValue";

console.log(object);
// { example: "ExampleValue went through proxy" }
// The target is object. proxied.target is not the target.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents