This file contains 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
'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 |
This file contains 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
'use strict'; | |
const Dog = { | |
name: 'Rocky', | |
age: 2 | |
}; | |
const createDog = (name, age) => Object.assign( | |
Object.create(Dog), | |
{ name, age } |
This file contains 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 Reader (file) { | |
this.file = file; | |
} | |
var reader = new Reader('data.txt'); |
This file contains 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
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 |
This file contains 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 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 |
This file contains 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 Reader (file) { | |
this.file = file; | |
this === global; // false | |
this === window; // false | |
} | |
var r = new Reader('data.txt'); |
This file contains 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 reader = { | |
data: 'Lorem Ipsum', | |
log() { | |
console.log(this.data); | |
} | |
}; | |
reader.log(); // 'Lorem Ipsum' |
This file contains 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 app = { | |
cache() { | |
this.el = document.querySelector('#some-id'); | |
this.bindElements(); | |
} | |
bindElement() { | |
this.el.addEventListener('click', this.handleClick); | |
}, | |
handleClick() { | |
alert('¡No toques mis cosas!'); |
This file contains 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 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!'); |
This file contains 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
// 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; |
OlderNewer