watch
优质
小牛编辑
124浏览
2023-12-01
Watches for all changes to a specified property (or properties) of an object and produces a sequence whose elements have the properties { property, value }
indicating which property changed and what it was changed to.
Note that this method only works on directly wrapped objects; it will not work on any arbitrary ObjectLikeSequence.
Signature
ObjectLikeSequence.watch = function(propertyNames) { /*...*/ }
ObjectLikeSequence.watch = function watch(propertyNames) { throw new Error('You can only call #watch on a directly wrapped object.'); }
Name | Type(s) | Description |
---|---|---|
propertyNames | string|Array? | A property name or array of property names to watch. If this parameter is |
returns | Sequence | A sequence comprising |
Examples
var obj = {}, changes = []; Lazy(obj).watch('foo').each(function(change) { changes.push(change); }); obj.foo = 1; obj.bar = 2; obj.foo = 3; obj.foo; // => 3 changes; // => [{ property: 'foo', value: 1 }, { property: 'foo', value: 3 }]