Skip to content

Instantly share code, notes, and snippets.

@bilalucar
Created April 17, 2017 16:41
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/6646f3c8f766dc36ad51e2726ce736c9 to your computer and use it in GitHub Desktop.
Save bilalucar/6646f3c8f766dc36ad51e2726ce736c9 to your computer and use it in GitHub Desktop.
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