利用原型共享数据
//什么样的数据需要写在原型当中
//需要共享的数据需要写在原型中
//属性需要共享 方法也需要共享
//不需要共享的数据写在构造函数中,需要共享的数据写在原型中
//构造函数
function Student(name,age,sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
//所有人的身高都是188 所有人的体重都是55
//所有的学生每天都要写500行代码
//所有的学生每天都要吃十斤西瓜
//原型对象
Student.prototype.height = "188";
Student.prototype.weight = "55kg";
Student.prototype.study = function(){
console.log("xuexi");
}
Student.prototype.eat = function () {
console.log("10kg");
}
//实例化对象并初始化
var stu = new Student("aa",58,"2");
console.dir(Student)
console.dir(stu)
stu.eat();
stu.study();