javascript与php观察者模式
a. 代码:
var a = function(){this.int = 0this.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. 输出:
0not 0
PHP:
a. 代码:
<?phpclass 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. 输出:
0not 0
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。