Skip to content

Instantly share code, notes, and snippets.

@jcblw
Created December 28, 2013 06:00
Show Gist options
  • Save jcblw/8156515 to your computer and use it in GitHub Desktop.
Save jcblw/8156515 to your computer and use it in GitHub Desktop.
Small getter setter pattern
var obj = {
get x() {
return this.value || 5;
},
set x(y) {
this.value = 2 * y
}
};
console.log( obj ); // { }
console.log( obj.x ); // 5
obj.x = 5;
console.log( obj.x ); // 10
console.log( obj ); // { value : 10 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment