function observable (value, condition, callback){ this.value = value; this.condition = condition; this.callback = callback;}observable.prototype = { get value () { return this._value; }, set value (value) { this._value = value; if (this.condition && this.callback && this.condition (value)) { this.callback (value); } }};condition = function (value) { console.log ('condition', value); return value === 2;}callback = function (value) { console.info ('Big Brother is watching you!');}var a = new observable (0, condition, callback);console.log ('set value to 1');a.value = 1;console.log ('set value to 2');a.value = 2;console.log ('set value to 3');a.value = 3;
转载请注明原文地址: https://ibbs.8miu.com/read-2226460.html