javascript - observer 范例
来源:互联网 发布:python三维图 编辑:程序博客网 时间:2024/06/05 04:16
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;
- javascript - observer 范例
- Observer pattern in Javascript
- JavaScript Observer Pattern 接口
- Observer pattern in JavaScript
- JavaScript使用手册、范例
- JavaScript实用范例辞典
- javascript操作cookie范例
- javascript Xml操作范例
- 实现范例的Observer设计模式 事件 委托
- JavaScript实用范例辞典 (試讀)
- JavaScript网页特效范例目录
- JavaScript设计模式学习——Observer
- JavaScript模式之观察者模式(Observer Pattern)
- Js-JavaScript 观察者设计模式 Observer Pattern
- Observer
- observer
- Observer
- Observer
- JPA - 一对多自身映射
- 在Visual C++中使用内联汇编
- oracle index学习总结
- 理解你想要做什么,明确你正在做什么
- 广播接收器-BroadcastReceiver 电池电量显示
- javascript - observer 范例
- 对话框以字符串形式显示
- 2011-2-27
- 在VC++2005中内嵌汇编
- JAVA.Util.ArrayList
- 一个简单继承的例子,面试失败的教训
- 分享Windows系统Vim编辑器乱码解决分析[转]
- About myself
- 内核定时器(2.6.23)