Created
December 1, 2012 03:02
-
-
Save fiveisprime/4180358 to your computer and use it in GitHub Desktop.
lookout.js example
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 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