Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View alejandrolechuga's full-sized avatar
🤯
Focusing

neptuno alejandrolechuga

🤯
Focusing
View GitHub Profile
@alejandrolechuga
alejandrolechuga / index.html
Created March 5, 2019 05:06
Generador Infinito Asincrono
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="container"></div>
</body>
@alejandrolechuga
alejandrolechuga / Example.js
Last active March 2, 2019 23:24
Iterables and iterators
const arr = ['a', 'b', 'c'];
const iterador = arr[Symbol.iterator]();
iterador.next();
// { value: 'a', done: false }
iterador.next();
// { value: 'b', done: false }
iterador.next();
// { value: undefined, done: true }
/// Only for linear data strutures
(function() {
var CSS_CLASS_DELIM, QuickdrawError, VirtualDomNode, dispatchEvent, exports, qd, qdInternal,
slice = [].slice,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
hasProp = {}.hasOwnProperty;
qd = {};
if (typeof window !== "undefined" && window !== null) {
if (window.qd != null) {
// Promesas (Promises) ES6
// XHR request XMLHttpRequest
// cross domain request
// https://www.mocky.io/
function request(url){
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
function random(){
return Math.floor(Math.random() * 10);
}
function getJSON() {
return new Promise(function (resolve, reject) {
setTimeout(() => resolve('Yes'),random());
setTimeout(() => reject('No'), random());
});
}
@alejandrolechuga
alejandrolechuga / getter-setters.js
Created February 11, 2019 02:13
getters and setters
/* jshint esnext: true */
// getters y setters
var persona = {
name: 'alejandro',
lastname: 'amador',
get fullname() {
return `${this.name} ${this.lastname}`
},
set fullname(fullvalue) {
@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();
}