Skip to content

Instantly share code, notes, and snippets.

@fiveisprime
Created December 1, 2012 03:02
Show Gist options
  • Select an option

  • Save fiveisprime/4180358 to your computer and use it in GitHub Desktop.

Select an option

Save fiveisprime/4180358 to your computer and use it in GitHub Desktop.
lookout.js example
var myObject = { id: 100, name: 'my object' };
// Subscribe to changes to all properties of the myObject object.
// The callback accepts the property name along with the previous and current value
// of the property.
lookout(myObject, function(prop, oldValue, newValue) {
// Log the name of the property that changed and it's previous/current value.
console.log(prop + ' just changed from [' + oldValue + '] to [' + newValue + ']');
});
// Subscribe to changes on specific properties:
// An array of properties.
lookout(myObject, ['id', 'name'], function(prop, oldValue, newValue) {
console.log(prop + ' just changed from [' + oldValue + '] to [' + newValue + ']');
});
// A single property.
lookout(myObject, 'id', function(prop, oldValue, newValue) {
console.log(prop + ' just changed from [' + oldValue + '] to [' + newValue + ']');
});
// Discontinue property change notifications.
disregard(myObject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment