Created
July 18, 2015 22:10
-
-
Save robpataki/68d16324708ce3887818 to your computer and use it in GitHub Desktop.
Very simple implementation of the singleton pattern in requirejs
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
define( | |
[], | |
function() { | |
'use strict'; | |
var instance = null; | |
function Singie() { | |
if(!!!instance){ | |
this.initialize(); | |
instance = this; | |
} | |
window.SINGIE = instance; // Good to have reference on window | |
return instance; | |
}; | |
Singie.prototype = { | |
initialize: function() { | |
this.hello = 'Hello' | |
this.world = 'World' | |
this.sayHello = function sayHello() { | |
return this.hello + ' ' + this.world; | |
} | |
} | |
}; | |
return Singie; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use the singleton instance:
To test if it is indeed a sole singleton instance: