Last active
December 22, 2016 16:09
-
-
Save maurobringolf/1c4d7c1fb10e841f2c1a3606a445fd51 to your computer and use it in GitHub Desktop.
Getter and Setter methods for object properties in JavaScript: https://medium.com/@maurobringolf/javascript-data-encapsulation-and-property-getter-and-setter-methods-a59cbddf2ef4#.qimkogc2u
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
//defining a normal property o.x using getters and setters | |
var o = { | |
c: 1, | |
get x() { return this.c; }, | |
set x(y) { this.c = y; } | |
} | |
o.x; //1 | |
o.x = 3; | |
o.x; //3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment