首页 > 编程语言 > 详细

JAVASCRIPT与PHP观察者模式

时间:2018-03-21 11:22:33      阅读:181      评论:0      收藏:0      [点我收藏+]
  • JAVASCRIPT:
    a. 代码:
    var a = function(){
    this.int = 0
    this.add = function(int){
        this.int = int
    }
    this.watch = function(){
        if(this.int==0){
            console.log(‘0‘)
        }else{
            console.log(‘not 0‘)
        }
    }
    }
    var a = new a()
    a.watch()
    a.add(1)
    a.watch()

    b. 输出:

    0
    not 0
  • PHP:
    a. 代码:
    <?php
    class a{
    public $int = 0;
    public function add($int){
        $this->int += $int;
    }
    public function watch(){
        if($this->int==0){
            echo "0".PHP_EOL;
        }else{
            echo "not 0".PHP_EOL;
        }
    }
    }
    $a = new a();
    $a->watch();
    $a->add(1);
    $a->watch();

    b. 输出:

    0
    not 0
  • JAVASCRIPT与PHP观察者模式

    原文:http://blog.51cto.com/12173069/2089256

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
    © 2014 bubuko.com 版权所有
    打开技术之扣,分享程序人生!