javascript与php单例模式
一、JAVASCRIPT:
- 代码:
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()
- 输出:
ab
二、PHP:
- 代码:
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;
- 输出:
ab abab
名称栏目:javascript与php单例模式
新闻来源:http://myzitong.com/article/jheigh.html