javascript与PHP动态往类中添加方法对比
程序员文章站
2022-07-10 17:49:55
1.javascript:
a. 代码:
var a = function(){
}
var my_a = new a()
my_a.say = fu...
1.javascript:
a. 代码:
var a = function(){ } var my_a = new a() my_a.say = function(){ console.log('hello') } my_a.say()
b. 输出:
hello
2. php:
a. 代码:
<?php class a{ } $a = new a(); $a->say = function(){ echo "hello"; }; $say = $a->say; $say();
b. 输出:
hello
上一篇: 单利模式及python实现方式详解