observer pattern in javascript
2008-10-13 16:00
344 查看
本来是想放在google的blog上面,试用一下的。没想到在发布的时候google的编辑器不允许包含有脚本标签等,还是放在这儿吧。以后有时间自己好好写一个blog系统。
1 <script type="text/javascript"> 2 window.onload=function(){ 3 var b=new B(); 4 5 var a = new A(); 6 a.i = "the 1st object will be show" 7 b.attObj(a);//object a be attach 8 9 var a1 = new A(); 10 a1.i = "the 2nd object will be show" 11 b.attObj(a1);//object b be attach 12 13 //invoke method of object b 14 b.m1(); 15 } 16 function A(){ //class A be defined 17 this.i=1; 18 var _this=this; 19 this.m1=function(){ 20 alert(this.i); 21 } 22 } 23 24 function B(){ 25 this.extObj = []; 26 this.attObj = function(obj){ 27 this.extObj.push(obj); 28 } 29 this.m1=function(){ 30 //when all operation of object B be finished,all <span class="dict18">subscriber will be notify</span>. 31 for(var i=0;i<this.extObj.length;i++){ 32 this.extObj[i].m1(); 33 } 34 } 35 } 36 37 </script>
相关文章推荐
- Observer pattern in JavaScript
- Observer Pattern in JavaScript II scope declared when subscribe()
- Observer pattern in JavaScript
- Observer pattern in Javascript
- Observer Design Pattern in C#!
- Observer Design Pattern in C#!
- JavaScript模式之观察者模式(Observer Pattern)
- The Decorator Pattern in Javascript
- JavaScript Module Pattern: In-Depth
- Understanding and Implementing Observer Pattern in C++
- The Flyweight Pattern in Javascript
- JavaScript Observer Pattern
- Js-JavaScript 观察者设计模式 Observer Pattern
- Observer Design Pattern Using JavaScript
- The Facade Pattern in Javascript
- JavaScript Module Pattern: In-Depth
- JavaScript Module Pattern: In-Depth
- Observer Pattern in Android
- 转载翻译文章:JavaScript Module Pattern: In-Dept
- JavaScript Observer Pattern 接口