Skip to content

Instantly share code, notes, and snippets.

View alejandrolechuga's full-sized avatar
🤯
Focusing

neptuno alejandrolechuga

🤯
Focusing
View GitHub Profile
@alejandrolechuga
alejandrolechuga / extendFromProto.js
Created February 9, 2019 09:38
Extend from proto
/* jshint esnext: true */
function Element(tipo) {
this.element = document.createElement(tipo);
}
Element.prototype.destroy = function(){
var parent = this.element.parentNode;
parent.removeChild(this.element);
this.element = null;
}
@alejandrolechuga
alejandrolechuga / clases.js
Created February 9, 2019 07:34
clases en javascript
/* jshint esnext: true */
// class ES6
class Button {
constructor(label, callback) {
this.label = label;
this.callback = callback;
this.html = this.createHTML();
this.bindEvents();
}
onClick() {
@alejandrolechuga
alejandrolechuga / proto.js
Created February 7, 2019 07:28
ejemplo cadena proto
var a = {
valor: 'Hola'
};
var b = {
proto: a
};
var c = {
proto: b
};
function objectCreate(o) {
function Helper() {}
Helper.prototype = o;
return new Helper();
}
// 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}`);
};