Skip to content

Instantly share code, notes, and snippets.

@bilalucar
Created April 17, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bilalucar/5d94aa995af8d4c42ef7aeec75895823 to your computer and use it in GitHub Desktop.
Save bilalucar/5d94aa995af8d4c42ef7aeec75895823 to your computer and use it in GitHub Desktop.
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