Created
January 31, 2015 08:54
-
-
Save rayshih/47ac37665c2b442bcccd to your computer and use it in GitHub Desktop.
Proactive vs Reactive
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
// 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