Skip to content

Instantly share code, notes, and snippets.

@codejets
Last active March 28, 2016 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codejets/695895ff03a6b8d566ee to your computer and use it in GitHub Desktop.
Save codejets/695895ff03a6b8d566ee to your computer and use it in GitHub Desktop.
Singleton Pattern
// 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