Created
July 5, 2013 00:43
-
-
Save addyosmani/5930976 to your computer and use it in GitHub Desktop.
O.o() quick example
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 records = []; | |
var obj = {}; | |
var obj2 = {}; | |
function observer(r){ | |
[].push.apply(records, r); | |
console.log(r); | |
} | |
Object.observe(obj, observer); // Begin observing changes | |
obj.foo = 41; // triggers a new notification (name: foo, type: "new", object {foo: 41}) | |
obj2.foo = 42; // does not trigger a notification | |
obj.foo = 43; // triggers an update notification (name: foo, type: "updated", oldValue: 41, object {foo: 43}) | |
Object.unobserve(obj, observer); // Stop observing changes | |
obj.foo = 44; // does not trigger a notification |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment