Last active
May 10, 2016 16:37
-
-
Save diegocasmo/3f01fcca8dc186214d2e to your computer and use it in GitHub Desktop.
Defining a backbone model with the singleton pattern. Useful for models that represent things such as the "AppState".
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
define([ | |
'underscore', | |
'backbone' | |
], function (_, Backbone) { | |
var Singleton = Backbone.Model.extend({ | |
}, { | |
singleton: null, | |
getInstance: function() { | |
Singleton.singleton = Singleton.singleton || new Singleton; | |
return Singleton.singleton; | |
} | |
}); | |
return Singleton; | |
}); | |
// usage | |
// var model = Singleton.getInstance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment