Buenas caballeros! De seguido junto al post de como Crear Prototipos Abstractos y funciones Virtuales en Javascript?.
Creo un nuevo post para ver como tratar el polimorfismo en Js, esta vez tratando un supuesto , que es el siguiente : http://w3processing.com/index.php?subMenuItemId=329
Hay exponen un "supuesto" de como tratar un método polimorficamente en Javascript, aquí el código que ellos exponen :
Código Javascript
:
Ver originalfunction Person(age, weight) {
this.age=age;
this.weight=weight;
this.getInfo=function() {
return "I am " + this.age + " years old " +
"and weighs " + this.weight +" kilo.";
}
}
function Employee(age, weight, salary){
this.salary=salary;
this.age=age;
this.weight=weight;
this.getInfo=function() {
return "I am " + this.age + " years old " +
"and weighs " + this.weight +" kilo " +
"and earns " + this.salary + " dollar.";
}
}
Employee.prototype= new Person();
Employee.prototype.constructor=Employee;
// The argument, 'obj', can be of any kind
// which method, getInfo(), to be executed depend on the object
// that 'obj' refer to.
function showInfo(obj) {
document.write(obj.getInfo()+"<br>");
}
var person = new Person(50,90);
var employee = new Employee(43,80,50000);
showInfo(person);
showInfo(employee);
Dado el siguiente Supuesto y habiéndolo ejecutado, pregunto ¿realmente no están sobrescribiendo el método padre ? , yo no veo polimorfismo por ningún lado. Si la respuesta a mi pregunta es negativa, por favor, explicadme donde está el uso del polimorfismo en ese código.
De ser afirmativa, que alguien pueda tratar un ejemplo verdadero de polimorfismo y explicarlo. Gracias.