类的声明
类的定义
类的继承 prototype关键字 链条式继承 公共空间
类的声明
function Person(name,age){
this.name = name;
this.age = age;
this.fav = “唱歌”;
// this.test = function(a){
// alert(a);
// }
}
function User(uname,upassword){
this.uname = uname;
this.upassword = upassword;
}
Person.prototype.test = function(){ alert("嘿嘿"); }
Person.prototype.user = new User();
User.prototype.testu = function(){ alert("我是use")}
类的使用
var p1 = new Person(“张三”,12);
var p2 = new Person(“李四”,23);
p1.adderss = “北京”;
alert(p1.name);
alert(p1.adderss);
alert(p1.test);
alert(p1.fav === p2.fav);
alert(p1.test === p2.test);
alert(p1.test === p2.test);
alert(p1.user.testu);
链条式继承
p1.user.testu();