Skip to content

Instantly share code, notes, and snippets.

@devarajchidambaram
Created March 15, 2018 05:14
Show Gist options
  • Save devarajchidambaram/cfa47a4120c47a0e5c94533ae158cc9c to your computer and use it in GitHub Desktop.
Save devarajchidambaram/cfa47a4120c47a0e5c94533ae158cc9c to your computer and use it in GitHub Desktop.
Proxy in nodejs
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