Created
January 14, 2014 04:36
-
-
Save amhed/8413094 to your computer and use it in GitHub Desktop.
Ejemplo del constructor design pattern en javascript
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
var ConstructorName = (function() { | |
'use strict'; | |
var variablePrivada = 0; | |
function ConstructorName(args) { | |
// enforces new | |
if (!(this instanceof ConstructorName)) { | |
return new ConstructorName(args); | |
} | |
// constructor body | |
this.miPropiedad = "Lo que yo quiera"; //Asi se retorna un objeto | |
} | |
ConstructorName.prototype.methodName = function(args) { | |
// Pero cualquier variable privada que yo haya declarado es | |
// visible desde este modulo, por lo que puedo usar la | |
// asignacion de metodos al objeto prototype y así no me sale | |
// el modelo "sucio" con todos los métodos cuando lo despliego en un debug screen | |
}; | |
return ConstructorName; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment