为什么我按老师的代码写,却没有输出相应的值,name,age都是undefined呢?求帮助

来源:8-1 概念与继承

小不点fly

2016-03-30 10:50

<!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>


写回答 关注

1回答

  • qq_覗水翛_0
    2016-03-30 18:42:40
    已采纳

    你有两个地方错了,一个地方少了一个逗号,一个地方少了一个this,看图,改过来过后可以正常显示。http://img.mukewang.com/56fbad920001ab2710400204.jpg

    小不点fly

    非常感谢!

    2016-03-31 14:01:54

    共 1 条回复 >

JavaScript深入浅出

由浅入深学习JS语言特性,且解析JS常见误区,从入门到掌握

281102 学习 · 1020 问题

查看课程

相似问题