Created
April 17, 2017 16:36
-
-
Save bilalucar/5d94aa995af8d4c42ef7aeec75895823 to your computer and use it in GitHub Desktop.
JavaScript 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 = { | |
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