Created
September 15, 2015 08:49
-
-
Save garlicnation/6cc066375224d10347b6 to your computer and use it in GitHub Desktop.
behavior singleton model
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
(function(){ | |
var SocketConnection = function() { | |
this.connection = instanceConnection(); | |
}; | |
// This is a globally shared connection. | |
var singletonConnection = null; | |
window.SocketConnectionBehavior = { | |
properties: { | |
connection: { | |
type: Object, | |
value: function() { | |
return getConnection(); | |
} | |
} | |
}, | |
// This function returns the global connection and creates an instance of it if necessary. | |
getConnection: function() { | |
if (singletonConnection === null) { | |
singletonConnection = new SocketConnection(); | |
} | |
return singletonConnection; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment