作用:原型来添加方法,解决数据共享,节省内存空间
function per(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
//简单的原型写法
// 将需要共享的数据都写在原型里
per.prototype = {
//手动修改构造器的指向
constructor:per,
height: "168",
weight: "55kg",
hobby: function () {
console.log("爱旅游爱撸串");
},
eat: function () {
console.log("我们都爱吃火锅");
}
};
var lut=new per("甜甜圈",23,"女");
lut.eat();
lut.hobby();
console.dir(per);
console.dir(lut);