-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23-herencia.js
More file actions
28 lines (23 loc) · 774 Bytes
/
23-herencia.js
File metadata and controls
28 lines (23 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function Persona(nombre, apellido, altura){
this.nombre = nombre;
this.apellido = apellido;
this.altura = altura;
}
Persona.prototype.saludar = function() {
console.log(`Hola mi nombre es ${this.nombre} ${this.apellido}`)
}
function Desarrollador(nombre, apellido) {
this.nombre = nombre;
this.apellido = apellido;
}
//herencia prototipal complicada
function heredaDe(prototipoHijo, prototipoPadre) {
var fn = function () {}
fn.prototype = prototipoPadre.prototype;
prototipoHijo.prototype = new fn;
prototipoHijo.prototype.constructor = prototipoHijo;
}
heredaDe(Desarrollador, Persona);
Desarrollador.prototype.saludar = function () {
console.log(`Hola mi nombre es ${this.nombre} ${this.apellido} y soy desarrollador`);
}