Last active
March 7, 2016 16:39
-
-
Save mmfilesi/c51cd271c85535841efb to your computer and use it in GitHub Desktop.
patrones
This file contains hidden or 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'; | |
/* 1. Closures */ | |
(function () { | |
var privateVar = "foo"; | |
})(); | |
console.log(privateVar); // Uncaught ReferenceError: privateVar is not defined | |
/* 2. patrón módulo */ | |
var miModulo = (function () { | |
var propiedadPrivada = "foo"; | |
return { | |
getPropiedadPrivada: function () { | |
return propiedadPrivada; | |
}, | |
setPropiedadPrivada: function(nuevoValor) { | |
propiedadPrivada = nuevoValor; | |
} | |
}; | |
})(); | |
miModulo.setPropiedadPrivada("bar"); | |
console.log(miModulo.getPropiedadPrivada()); // bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bibliografía