Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Last active December 29, 2020 01:24
Show Gist options
  • Save Jagathishrex/b8315761b8bad36885d919133b342fb5 to your computer and use it in GitHub Desktop.
Save Jagathishrex/b8315761b8bad36885d919133b342fb5 to your computer and use it in GitHub Desktop.
"use strict";
let user = {
name : "Jagathish",
age : 23,
mobile : 123123123,
address : "221B Baker Stree, London"
};
let handler = {
set(target, prop, val){
if(prop in target){
target[prop] = val;
return true; // if the proprty is changed return true
} else {
return false; // if the proprty is not changed return false
}
}
};
user = new Proxy(user, handler);
user.age = 24;
console.log(user.age);//24
user.sex = "Male";
console.log(user.sex); //undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment