<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
function Person(name,age){
console.log(this);
this.name = name;
this.age = age;
this.getName = function(){
console.log(this.name);
}
this.getage = function(){
console.log(this.age);
}
}
Person();
function Student(name,age,num){
Person.call(this,name,age);
}
var p1 = new Person("xyf",18);
//p1.getName();
</script>
</body>
</html>
JavaScript中,this是当前对象。
你的代码有问题,输出的 undefined。