Skip to content

Instantly share code, notes, and snippets.

@MylesBorins
Created June 8, 2016 18:28
Show Gist options
  • Save MylesBorins/c9077089e07921ef1f688bacb329b485 to your computer and use it in GitHub Desktop.
Save MylesBorins/c9077089e07921ef1f688bacb329b485 to your computer and use it in GitHub Desktop.
Getter / Setter
var obj = {
_a: 0
};
Object.defineProperty(obj, 'a', {
get: function () {
return this._a;
},
set: function (val) {
this._a = val;
console.log('Updated a to', this._a)
}
});
var obj = {
_a: 7,
get a() {
return this._a;
},
set a(val) {
this._a = val;
console.log('Updated a to', this._a)
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment