1. JavaScript中没有类的语法,是用函数闭包(closure)模拟出来的;
2. JavaScript中String, Data等“类”都被叫做“对象”;
3. JavaScript中声明类,类不是类,是对象;
4. 例如:
function Person(name,age){
this.name = name;
this.age = age;
this.SayHello = function(){
alert("你好,我是"+this.name+",我“+this.age+"岁了”);
}
}
var p1 = new Person("tom",20);
p1.SayHello( );
|