Skip to content

Instantly share code, notes, and snippets.

View alejandrolechuga's full-sized avatar
🤯
Focusing

neptuno alejandrolechuga

🤯
Focusing
View GitHub Profile
// Clase base
function Person(name, age) {
this.name = name;
this.age = age;
this.config = function () {};
}
Person.prototype.getName = function () {
return this.name;
};
@alejandrolechuga
alejandrolechuga / eje8.js
Created February 6, 2019 05:49
prototype
function Doctor(name, age) {
Person.call(this, name, age);
}
@alejandrolechuga
alejandrolechuga / eje7.js
Created February 6, 2019 05:45
prototype
function Doctor(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);
@alejandrolechuga
alejandrolechuga / eje6.js
Last active February 6, 2019 05:27
Prototype
function Doctor() {
}
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'
@alejandrolechuga
alejandrolechuga / eje6.js
Last active February 6, 2019 05:26
Prototype
// Clase base
function Person(name, age) {
this.name = name;
this.age = age;
this.config = function () {};
}
Person.prototype.getName = function () {
return this.name;
};
@alejandrolechuga
alejandrolechuga / eje5.js
Created February 5, 2019 04:54
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}`);
};
@alejandrolechuga
alejandrolechuga / eje4.js
Last active February 4, 2019 03:43
Prototype
var Mamifero = {
tipo: 'desconocido',
getTipo: function () {
return this.tipo;
}
};
var humano = Object.create(Mamifero);
// Sobre-escribimos el tipo
humano.tipo = 'humano';
@alejandrolechuga
alejandrolechuga / eje3.js
Last active February 4, 2019 01:47
Prototype
function Book(name, year) {
// propiedades
this.name = name;
this.year = year;
}
// metodos
Book.prototype.getName = function () {
return this.name;
};
@alejandrolechuga
alejandrolechuga / eje2.js
Created February 4, 2019 01:29
prototype ejemplo
var libro = new Book('Don quijote', 1612);
var libro2 = new Book('Señor de los anillos', 1930);
// Cuando comparamos
libro.getName === libro2.getName; // false