Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function MyObject() {
- Object.defineProperty(this, 'accessA', {
- set(x) {
- if (x>0) this.a = x; // or whatever validation you want
- },
- get() { return this.a; }
- })
- }
- var obj1 = new MyObject();
- obj1.accessA=77; // call the setter
- console.log(obj1.accessA); // call the getter
Advertisement
Add Comment
Please, Sign In to add comment