javascript 中没有类的语法,是用函数闭包(closure) 模拟出来的,我们知道javascript
中string ,Date 等“类”都被叫做“对象”,不严谨...
javascript 中声明类(类不是类,是对象)
例如:
<script type="text/javascript">
function Person(name,age){
this.Name=name;
this.Age=age;
this.SayHello=function(){alert("你好,我是"+this.Name)}
}
var p1=new Person("小明",30);
p1.Gender="男";//动态增加属性!
p1.SayHello();
alert(p1.Gender); </script>
this.Name 就是动态增加对象!

浙公网安备 33010602011771号