Created
February 6, 2019 05:53
-
-
Save alejandrolechuga/36e33dd3ef774d80a8ea5eb7c5c6e895 to your computer and use it in GitHub Desktop.
prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clase base | |
function Person(name, age) { | |
this.name = name; | |
this.age = age; | |
this.config = function () {}; | |
} | |
Person.prototype.getName = function () { | |
return this.name; | |
}; | |
Person.prototype.getAge = function () { | |
return this.age; | |
}; | |
Person.prototype.saludo = function () { | |
console.log(`Hola soy ${this.getName()} tengo ${this.getAge()}`); | |
}; | |
var alejandro = new Person('Alejandro', 12); | |
alejandro.saludo(); // 'Hola soy Alejandro tengo 12' | |
function Doctor(name, age) { | |
Person.call(this, name, age) | |
} | |
Doctor.prototype = Object.create(Person.prototype); | |
Doctor.prototype.saludo = function() { | |
console.log(`Saludos soy el doctor ${this.getName()} y tengo ${this.getAge()} años`); | |
}; | |
var doctorAlejandro = new Doctor('Alejandro', 33); | |
doctorAlejandro.saludo(); // 'Saludos soy el doctor Alejandro y tengo 33 años' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment