Created
February 5, 2019 04:54
-
-
Save alejandrolechuga/89167326f0ef2e3f9a8c2a29e8377bdb 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
// Super clase | |
function Person(name, age) { | |
this.name = name; | |
this.age = age; | |
this.config = function () {}; | |
} | |
Person.prototype.saludo = function () { | |
console.log(`Hola soy ${this.name} tento ${this.age}`); | |
}; | |
// Subclase | |
function Doctor(name, age) { | |
Person.call(this, name, age); | |
} | |
function Helper() {}; | |
Helper.prototype = Person; | |
Doctor.prototype = new Helper().prototype; | |
Doctor.prototype.saludo = function () { | |
console.log(`Saludo soy el Doctor ${this.name} tengo ${this.age}`); | |
}; | |
var alejandro = new Person('Alejandro', 12); | |
alejandro.saludo(); | |
console.log(alejandro); | |
var doctorAlejandro = new Doctor('Alejandro', 33); | |
doctorAlejandro.saludo(); | |
console.log(doctorAlejandro); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment