Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active December 10, 2015 10:38
Show Gist options
  • Save philmander/4422219 to your computer and use it in GitHub Desktop.
Save philmander/4422219 to your computer and use it in GitHub Desktop.
Injecting literal values as constructor arguments
//movies/move-finder.js
define(function() {
var MovieFinder = function(jsonUrl, numMovies, includeShortFilms) {
this.jsonUrl = jsonUrl;
this.numMovies = numMovies;
this.includeShortFilms = includeShortFilms;
};
return MovieFinder;
});
//app-config.js
define(function() {
return {
protos: {
movieFinder : {
module: "movies/movie-finder",
args: [
"http://json.movies.com", 20, true
]
}
}
};
});
require(["inverted", "app-config"], function(inverted, conf) {
var appContext = inverted.create(conf);
appContext.getProto("movieFinder", function(movieFinder) {
//movieFinder.jsonUrl == "http://json.movies.com
//movieFinder.numMovies == 20
//movieFinder.includeShortFilms == true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment