Created
July 30, 2016 14:27
-
-
Save sarbull/fad3a4d3feea9f0286d85c9feef65661 to your computer and use it in GitHub Desktop.
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 singleton = (function () { | |
var instance; | |
function init() { | |
function privateMethod(){ | |
console.log( "I am private" ); | |
} | |
var privateVariable = "I am a private variable"; | |
var privateRandomNumber = Math.random(); | |
return { | |
publicMethod: function () { | |
console.log( "I am a public method" ); | |
}, | |
publicProperty: "I am a public property", | |
getRandomNumber: function() { | |
return privateRandomNumber; | |
} | |
}; | |
}; | |
return { | |
getInstance: function () { | |
if ( !instance ) { | |
instance = init(); | |
} | |
return instance; | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment