Created
March 15, 2018 05:14
-
-
Save devarajchidambaram/cfa47a4120c47a0e5c94533ae158cc9c to your computer and use it in GitHub Desktop.
Proxy in nodejs
This file contains 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
let validator = { | |
set: function name(Obj, param, value) { | |
if(param === 'age'){ | |
if(! Number.isInteger(value)) throw new Error("age is not an number type") | |
if( !(value > 18 && value < 80)){ | |
throw Error("age range error, age must between 18 to 80 "); | |
} | |
} | |
return true; | |
} | |
} | |
var person = new Proxy({}, validator); | |
person.age = 23; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment