Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active December 10, 2015 10:39
Show Gist options
  • Select an option

  • Save philmander/4422560 to your computer and use it in GitHub Desktop.

Select an option

Save philmander/4422560 to your computer and use it in GitHub Desktop.
Demonstrates using singleton and static scopes to create movie utils
//movie/movie-util-instance.js
define(function() {
var MovieUtil = function() {
};
MovieUtil.prototype.doSomething = function() {
//dostuff
};
return MovieUtil;
});
//movie/movie-util-static.js
define(function() {
var movieUtil = {};
movieUtil.doStuff = function() {
//do stuff
};
return movieUtil;
});
//app-config.js
define(function() {
return {
protos: {
movieUtilInstance: {
module: "movies/movie-util-instance",
scope: "singleton"
},
movieUtilStatic: {
module: "movies/movie-util-static",
scope: "static"
}
}
};
});
require(["inverted", "app-config"], function(inverted, conf) {
var appContext = inverted.create(conf);
//get two singletons (same instance)
appContext.getProto(["movieUtilInstance" "movieUtilInstance"],
function(movieUtilOne, movieUtilTwo) {
//(movieUtilOne === movieUtilTwo) == true
movieUtilOne.doStuff();
});
//get as static (no instance created)
appContext.getProto("movieUtilStatic", function(movieUtil) {
movieUtil.doStuff();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment