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 cokePkt = cokePkt || {}; | |
cokePkt.greeting = { | |
hi: function hi() { | |
console.log('hi'); | |
}, | |
hello: function hello() { | |
console.log('hello'); | |
} | |
}; |
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(namespace){ | |
'use strict'; | |
function getName() { | |
return 'Lucas'; | |
} | |
namespace.greeting = { | |
hi: function hi() { | |
console.log('hi ' + getName()); | |
}, |
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
/* | |
O UMD verifica se você está usando AMD ou CommonJS. | |
Caso você não esteja usando nenhum desses dois, ele | |
adiciona seu módulo no objeto global. | |
*/ | |
(function (global, factory) { | |
// verifica se é AMD | |
if (typeof define === "function" && define.amd) { | |
define(["exports"], factory); | |
// verifica se é CommonJS |
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(global){ | |
const idade = 21; | |
const cpf = 13412312321; | |
function meuNomeQueSeraExposto() { | |
return 'Lucas'; | |
} | |
function meuNomeQueNaoSeraExposto() { | |
return 'Lucas Muniz Dutra'; | |
} |
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
define('meuModulo', ['lodash'], function(_) { | |
// código do módulo | |
return { | |
... | |
}; | |
}); | |
// os argumentos do módulo devem estar na mesma ordem do array de dependências | |
define('meuModulo', ['lodash', 'facebook'], function(_, fb) { | |
// código do módulo |
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
// carregando o lodash na variável _ | |
const _ = require('lodash'); | |
function meuModulo() { | |
} | |
// você pode retornar uma função, objeto ou uma variável. | |
// agora o meuModulo pode ser importado usando o require. | |
module.exports = meuModulo; |
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
/* | |
navegaremos de construtor a construtor até obter um erro | |
no final na prototype chain | |
*/ | |
var set = new Set(); | |
console.log(set); | |
// [] | |
console.log(set.constructor); | |
// ƒ Set() { [native code] } | |
console.log(set.__proto__.constructor); |
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 Veiculo(nome, valor, cor) { | |
this.nome = nome; | |
this.valor = valor; | |
this.cor = 'preto'; | |
}; | |
Veiculo.prototype.acelerar = function() { | |
console.log('aceleraaaaaa'); | |
} |
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
// agora a classe Ferrari extends Veiculo | |
Ferrari.prototype = Object.create(Veiculo.prototype); | |
// porém agora o constructor de Ferrari.prototype é igual | |
// ao de Veiculo.prototype... Precisamos resolver isso. | |
Ferrari.prototype.constructor = Ferrari; | |
let ff = new Ferrari(); | |
ff.acelerar() // works!! | |
Ferrari.prototype.constructor // Ferrari |
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
class Veiculo { | |
constructor(nome, valor, cor) { | |
this._nome = nome; | |
this._valor = valor; | |
this._cor = cor; | |
} | |
get cor() { | |
return this._cor; | |
} |
OlderNewer