Skip to content

Instantly share code, notes, and snippets.

@addyosmani
Created July 5, 2013 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save addyosmani/5930976 to your computer and use it in GitHub Desktop.
Save addyosmani/5930976 to your computer and use it in GitHub Desktop.
O.o() quick example
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