Skip to content

Instantly share code, notes, and snippets.

@aadsm
Created July 11, 2012 05:09
Show Gist options
  • Select an option

  • Save aadsm/3088137 to your computer and use it in GitHub Desktop.

Select an option

Save aadsm/3088137 to your computer and use it in GitHub Desktop.
Property Change Listeners in MontageJS
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