当我点击按钮时调用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