下面的输出次序为156,18,undifined,我想知道为什么最后有个undifined呢??
<!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” ”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Test</title>
<script language="JavaScript">
function person(){
this.name="张三";
}
function student(){
var age=18;
student.prototype.getage=function(){
alert(age);
}
}
function test(){ student.prototype = new person();
student.prototype.age=156;
var s=new student();alert(s.age);
alert(s.getage());}
</script> </head>
<body>
<a href="#" onclick="test()"> 链接一</a> </body>
</html>
<!DOCTYPE html PUBLIC ”-//W3C//DTD XHTML 1.0 Transitional//EN” ”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Test</title>
<script language="JavaScript">
function person(){
this.name="张三";
}
function student(){
var age=18;
student.prototype.getage=function(){
alert(age);
}
}
function test(){ student.prototype = new person();
student.prototype.age=156;
var s=new student();alert(s.age);
alert(s.getage());}
</script> </head>
<body>
<a href="#" onclick="test()"> 链接一</a> </body>
</html>
function Person(){ }
Person.prototype.hello = "hello";
Person.prototype.sayHello = function(){ alert(this.hello); }
function Student(){ }
Student.prototype = new Person();//这行的作用是:将Parent中将所有通过prototype追加的属性和方法都追加到Student,从而实现了继承
Student.prototype.world = "world";
Student.prototype.sayWorld = function(){ alert(this.world); }
var c = new Student();
c.sayHello();
c.sayWorld();