//使用prototype原型和构造函数方式定义对象,使多个对象拥有独立的属性并公用同一个方法
function Person(username,password)
{
this.username=username;
this.password=password;
}
//使用prototype给Person添加方法
Person.prototype.getInfo=function(){
alert(this.username+"......"+this.password);
}
var p=new Person("www","132456");
var p2=new Person("asd","456789");
p.getInfo();
p2.getInfo();
使用prototype原型和构造函数方式定义对象
最新推荐文章于 2019-10-24 09:38:08 发布