Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created February 6, 2019 05:53
Show Gist options
  • Save alejandrolechuga/36e33dd3ef774d80a8ea5eb7c5c6e895 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/36e33dd3ef774d80a8ea5eb7c5c6e895 to your computer and use it in GitHub Desktop.
prototype
// 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