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
| /* 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; | |
| } |
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
| /* jshint esnext: true */ | |
| // class ES6 | |
| class Button { | |
| constructor(label, callback) { | |
| this.label = label; | |
| this.callback = callback; | |
| this.html = this.createHTML(); | |
| this.bindEvents(); | |
| } | |
| onClick() { |
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
| var a = { | |
| valor: 'Hola' | |
| }; | |
| var b = { | |
| proto: a | |
| }; | |
| var c = { | |
| proto: b | |
| }; |
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
| function objectCreate(o) { | |
| function Helper() {} | |
| Helper.prototype = o; | |
| return new Helper(); | |
| } |
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
| // Clase base | |
| function Person(name, age) { | |
| this.name = name; | |
| this.age = age; | |
| this.config = function () {}; | |
| } | |
| Person.prototype.getName = function () { | |
| return this.name; | |
| }; |
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
| function Doctor(name, age) { | |
| Person.call(this, name, age); | |
| } |
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
| 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); |
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
| 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' |
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
| // Clase base | |
| function Person(name, age) { | |
| this.name = name; | |
| this.age = age; | |
| this.config = function () {}; | |
| } | |
| Person.prototype.getName = function () { | |
| return this.name; | |
| }; |
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}`); | |
| }; |