Last active
December 19, 2015 19:59
-
-
Save thomasboyt/6010501 to your computer and use it in GitHub Desktop.
js getters and setters
This file contains hidden or 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 o = {}; | |
Object.observe(o, function(records) { | |
console.log(records); | |
}); | |
// the following three changes are batched, as they occur | |
// within the same frame of the loop | |
o.x = "foo"; | |
o.y = "bar"; | |
o.z = "baz"; | |
// these two instances will be batched separately | |
// in their own frame | |
setTimeout(function() { | |
o.a = "bah"; | |
o.b = "blergh"; | |
}, 100); |
This file contains hidden or 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 o = { | |
"_x": "foo", | |
get x() { | |
return this._x; | |
}, | |
set x(val) { | |
this._x = val; | |
} | |
}; | |
console.log(o.x); // "foo" | |
o.x = "bar"; | |
console.log(o.x); // "bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment