Skip to content

Instantly share code, notes, and snippets.

@philmander
Created December 31, 2012 19:51
Show Gist options
  • Save philmander/4422231 to your computer and use it in GitHub Desktop.
Save philmander/4422231 to your computer and use it in GitHub Desktop.
Injecting literal values as a constructor argument using a map of values
//movies/move-finder.js
define(function() {
var MovieFinder = function(options) {
this.jsonUrl = options.jsonUrl || null;
this.numMovies = options.numMovies || 10;
this.includeShortFilms = options.includeShortFilms || false;
};
return MovieFinder;
});
//app-config.js
define(function() {
return {
protos: {
movieFinder : {
module: "movies/movie-finder",
args: [{
jsonUrl: "http://json.movies.com",
numMovies: 20,
includeShortFilms: 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