Last active
December 29, 2020 01:24
-
-
Save Jagathishrex/b8315761b8bad36885d919133b342fb5 to your computer and use it in GitHub Desktop.
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
"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