zoukankan      html  css  js  c++  java
  • observer pattern in javascript

    本来是想放在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 subscriber will be notify.
    31             for(var i=0;i<this.extObj.length;i++){
    32                 this.extObj[i].m1();
    33             }
    34         }
    35     }
    36 
    37     </script>


  • 相关阅读:
    postgresql procedure 存储过程
    Laravel Queues 队列应用实战
    解决IDEA内打开vim 乱码,git rebase -i 中文乱码
    Maven和maven-shade-plugin的小坑
    Spring+Mybatis 多套数据源实现
    【解决】Teamcity VCS git-upload-pack not permitted on "https://xxxx.com/slankka.git/"
    【Flink系列八】构建实时计算平台——动态加载UDF
    【Flink系列零】构建实时计算平台——FlinkSQL 作业菜鸟笔记
    【Flink系列七】构建实时计算平台——校验FlinkSQL
    【Flink系列六】构建实时计算平台——Flink 1.10+通过Kerberos连接HiveCatalog
  • 原文地址:https://www.cnblogs.com/sxlfybb/p/1310131.html
Copyright © 2011-2022 走看看