當我點擊按鈕時調用Func2。爲什麼我沒有彈出?我應該在第一次之後看到警報警報(「覆蓋1」)和警報(「覆蓋2」)嗎?JavaScript中的替代
// 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();
}
感謝
我想你應該查看[markdown editing help](http://stackoverflow.com/editing-help/)頁面。一個寫得好的問題會給你寫得很好的答案。 – zzzzBov 2012-07-30 15:03:06
什麼是'Func2'? – 2012-07-30 15:04:15
什麼按鈕?您還沒有張貼所謂的「測試2()」 – Pointy 2012-07-30 15:04:22