重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

javascript与php单例模式

一、JAVASCRIPT:

  1. 代码:
    var test = function (){
    this.str = '',
    this.a = function (){
        this.str += "a"
        return this
    },
    this.b = function(){
        this.str += "b"
        return this
    }
    this.out = function(){
        console.log(this.str)
    }
    }
    var entity = new test()
    entity.a().b().out()
  2. 输出:
    ab

    二、PHP:

  3. 代码:
    out .= $a;
        return $this;
    }
    public function b($b){
        $this->out .= $b;
        return $this;
    }
    public function say(){
        echo $this->out.PHP_EOL;
    }
    public function get(){
        return $this->out;
    }
    }
    $single = new single();
    $out = $single->a('a')->b('b')->say();
    $get = $single->a('a')->b('b')->get();
    echo $get;
  4. 输出:
    ab
    abab

文章名称:javascript与php单例模式
链接分享:http://cqcxhl.com/article/jheigh.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP