Func2 在我单击 button 时被调用。为什么我没有任何弹出窗口?我应该在第一个之后同时看到警报警报(“override1”)和警报(“override2”)吗?
// JavaScript Document
function person(name, surname) {
this.name = "";
this.surname = "";
this.age = "11";
this.setName(name);
this.setSurname(surname);
//alert('Person instantiated');
}
person.prototype.setName = function(name) {
this.name = "Sir1" + name;
}
person.prototype.setSurname = function(surname) {
this.surname = "-" + surname;
}
person.prototype.setAge = function(newAge) {
this.age = newAge;
}
person.prototype.show = function() {
alert("override1");
}
function employee(name, surname, company) {
//if (arguments[0] === inheriting) return;
person.call(this, name, surname); // -> override del costruttore
//this.name = "Sir2"+name;
this.company = company;
};
employee.prototype.show = function() {
person.prototype.show;
alert("override2");
}
function test2() {
employee.prototype = new person();
// correct the constructor pointer because it points to Person
employee.prototype.constructor = employee;
// Crea un oggetto impiegato da persona
impiegato = new employee("Antonio", "Di Maio", "Consuldimo");
//impiegato.show();
impiegato.show();
}
谢谢