Skip to content

Instantly share code, notes, and snippets.

View mishelashala's full-sized avatar

Michell Ayala mishelashala

  • Mérida, Yucatan
View GitHub Profile
@mishelashala
mishelashala / index.js
Last active November 8, 2015 07:49
OLOO JavaScript
'use strict';
// Worker as a module, not as an object.
// Encapsulates behavior.
const Worker = require('./worker');
// Factory method instead of constructor
const jd = Worker.create('Jenny Doe', 19, 'CEO');
// Own properties
@mishelashala
mishelashala / dog.js
Last active July 25, 2018 20:42
OLOO Composition - JavaScript
'use strict';
const Dog = {
name: 'Rocky',
age: 2
};
const createDog = (name, age) => Object.assign(
Object.create(Dog),
{ name, age }
function Reader (file) {
this.file = file;
}
var reader = new Reader('data.txt');
this === window; // true si estás en un navegador, false en caso contrario
this === global; // true si estás en node // false en caso contrario
function Foo () {
return this;
}
Foo() === global; // true si estás en node, false en caso contario
Foo() === window; // true si estás en un navegador, false en caso contrario
function Reader (file) {
this.file = file;
this === global; // false
this === window; // false
}
var r = new Reader('data.txt');
var reader = {
data: 'Lorem Ipsum',
log() {
console.log(this.data);
}
};
reader.log(); // 'Lorem Ipsum'
var app = {
cache() {
this.el = document.querySelector('#some-id');
this.bindElements();
}
bindElement() {
this.el.addEventListener('click', this.handleClick);
},
handleClick() {
alert('¡No toques mis cosas!');
var app = {
cache() {
this.el = document.querySelector('#some-id');
this.bindElement();
},
bindElement() {
this.el.addEventListener('click', this.handleClick.bind(this));
},
handleClick(e) {
alert('NO toques mis cosas!');
// incluyo iostream para entradas y salidas estándar
#include <iostream>
// incluyo string
#include <string>
int main () {
// declaro una variable de tipo string y le asigno "Hola mundo"
std::string str = "Hola mundo";
// redirecciono a la salida stándar el tamaño de str
std::cout << str.size << std::endl;