Skip to content

Instantly share code, notes, and snippets.

@diogomachado
Last active August 19, 2016 19:49
Show Gist options
  • Save diogomachado/f7b0de590d7d08a1d605e8f0967c6f15 to your computer and use it in GitHub Desktop.
Save diogomachado/f7b0de590d7d08a1d605e8f0967c6f15 to your computer and use it in GitHub Desktop.
Padrão de projeto Javascript (Module Pattern)
// Exemplo com encapsulamento de métodos
var pedidoMesa1 = (function() {
var pedido = {};
pedido.alertar = function(msg){
alert(msg);
};
pedido.addItem = function(){
return pedido.alertar('Produto adicionado');
};
pedido.rmItem = function(){
return pedido.alertar('Produto removido');
};
return {
addItem : pedido.addItem,
rmItem : pedido.rmItem
};
})();
pedidoMesa1.addItem();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment