Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created February 5, 2019 04:54
Show Gist options
  • Save alejandrolechuga/89167326f0ef2e3f9a8c2a29e8377bdb to your computer and use it in GitHub Desktop.
Save alejandrolechuga/89167326f0ef2e3f9a8c2a29e8377bdb to your computer and use it in GitHub Desktop.
Prototype
// 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