Last active
March 28, 2016 04:11
-
-
Save codejets/695895ff03a6b8d566ee to your computer and use it in GitHub Desktop.
Singleton Pattern
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
// Singleton Pattern | |
/* | |
In really simple terms, Singleton pattern is a initiation and caching service of your Object. | |
*/ | |
var Todo = (function() { | |
'use strict'; | |
var todo; | |
function createTodo() { | |
/* | |
You can add any object instantiation inside new Object here. | |
*/ | |
var todo = new Object(); | |
return todo; | |
} | |
/* | |
Creating a public method interface. | |
*/ | |
return { | |
get : function () { | |
/* | |
Get the singleton object is todo is already created or | |
new new object is created. | |
*/ | |
if (!todo) { | |
todo = createTodo(); | |
} | |
return todo; | |
} | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment