我以下列方式在JavaScript中应用继承:
var employee = function(name) {
this.name = name;
}
employee.prototype.getName = function() {
return this.name;
}
var pEmployee = function(salary) {
this.salary = salary;
}
pEmployee.prototype.getSalary = function() {
return this.salary;
}
var employee = new employee("mark");
pEmployee.prototype = employee;
var pe = new pEmployee(5000);
console.log(pe.getName());
console.log(pe.getSalary());Run Code Online (Sandbox Code Playgroud)
但它在控制台中显示以下错误:
未捕获的TypeError:pe.getSalary不是函数
谁能告诉我这个错误背后的原因是什么?