Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript Getters And Setters
var obj = {
foo: 'this is the value of foo',
getFoo: function() {
return this.foo;
},
setFoo: function(val) {
this.foo = val;
}
}
console.log(obj.getFoo());
// "this is the value of foo"
obj.setFoo('hello');
console.log(obj.getFoo());
// "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.