Created
April 17, 2017 16:41
-
-
Save bilalucar/6646f3c8f766dc36ad51e2726ce736c9 to your computer and use it in GitHub Desktop.
JS Keyword Getters And Setters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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