Created
July 11, 2012 05:09
-
-
Save aadsm/3088137 to your computer and use it in GitHub Desktop.
Property Change Listeners in MontageJS
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 bar = {a: {b: {c: 3}}}; | |
| // we're going to listen to changes of the bar.a.b.c value | |
| bar.addPropertyChangeListener("a.b.c", function() { | |
| console.log("bar.a.b.c was changed to: " + bar.a.b.c); | |
| }); | |
| bar.a.b.c = 4; // Outputs: bar.a.b.c was changed to: 4 | |
| bar.a = {b: {c: 6}}; // Outputs: bar.a.b.c was changed to: 6 | |
| bar.a.b.c = 3 + 3; // notification not fired, the value didn't change | |
| // a third parameter indicates that the listener should be called before | |
| // the change happens | |
| bar.addPropertyChangeListener("a.b.c", function() { | |
| console.log("bar.a.b.c is going to be changed from: " + bar.a.b.c); | |
| }, true); | |
| bar.a.b.c = 4; // Outputs bar.a.b.c is going to be changed from: 6 | |
| // bar.a.b.c was changed to: 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment