Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS Keyword Getters And Setters
var obj = {
fooVal: 'this is the value of foo',
get foo() {
return this.fooVal;
},
set foo(val) {
this.fooVal = val;
}
}
console.log(obj.foo);
// "this is the value of foo"
obj.foo = 'hello';
console.log(obj.foo);
// "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.