Skip to content

Instantly share code, notes, and snippets.

@rayshih
Created January 31, 2015 08:54
Show Gist options
  • Save rayshih/47ac37665c2b442bcccd to your computer and use it in GitHub Desktop.
Save rayshih/47ac37665c2b442bcccd to your computer and use it in GitHub Desktop.
Proactive vs Reactive
// proactive
var obj = {
a: 0,
b: 1
};
obj.a = 3;
obj.b = a + 1; // proactive
console.log(obj.b); // b = 4
// reactive
Object.observe(obj, function (changes){
obj.b = changes[0].object.a + 1;
});
obj.a = 5;
console.log(obj.b); // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment