<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>OOP</title>
</head>
<body>
<script type="text/javascript">
function Person(name,age){
this.name = name;
this.age = age;
}
Person.prototype.hi = function(){
document.write('Hi,my name is '+this.name+",I'm "+age+' years old now'+"<br>");
};
Person.prototype.LEGS_NUM = 2;
Person.prototype.ARMS_NUM = 2;
Person.prototype.walk = function(){
document.write(this.name+" is walking..."+"<br>");
};
function Student(name, age, className){
Person.call(this.name,age);
this.className = className;
}
Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;
Student.prototype.hi = function(){
document.write('Hi,my name is '+this.name+",I'm "+age+' years old now, and from '+this.className+"<br>");
};
Student.prototype.learn = function(subject){
document.write(this.name+' is learning '+subject+' at '+this.className+"<br>");
};
var jack = new Student('Jack',10,'Class 1,Grade 3'+"<br>");
jack.hi();
document.write(jack.LEGS_NUM+"<br>");
jack.walk();
jack.learn('Chinese');
</script>
</body>
</html>
你有两个地方错了,一个地方少了一个逗号,一个地方少了一个this,看图,改过来过后可以正常显示。