//复写Persion中的hi 方法 Student.prototype.hi = function(){ console.log("Hi my name is " + this.name + ", I'm " + this.age + " years old now, and from " + this.className + "." ); }
//定义Student中的learn 方法 Student.prototype.learn = function(subject){ console.log(this.name + " is learning " + subject + " at " + this.className); }
//实例化Student类 var jack = new Student("Jack", 27, 'Class 3, Greade 2');
jack.hi(); //Hi, my name is Jack, I'm 27 years old now, and from Class 3, Greade 2. jack.LEGS_NUM; // 2 jack.ARMS_NUM; // 2 jack.learn('math') // Jack is learning math at Class 3, Greade 2.