Skip to content

Instantly share code, notes, and snippets.

@philmander
Created December 31, 2012 20:18
Show Gist options
  • Select an option

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

Select an option

Save philmander/4422436 to your computer and use it in GitHub Desktop.
Injecting literal values and dependencies as properties and methods
//movies/movie-lister.js
define(function() {
var MovieLister = function() {
this.movieFinder = null;
this.includeShortFilms = false;
this.numMovies = 10;
};
MovieLister.prototype.setNumToShow = function(numToShow) {
this.numMovies = numToShow
};
return MovieLister;
});
//app-config.js
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
props: {
movieFinder: "*movieFinder",
includeShortFilms: true,
setNumToShow: 20,
}
},
movieFinder: {
module: "movies/movie-finder"
}
}
};
});
require(["inverted", "app-config"], function(inverted, conf) {
var appContext = inverted.create(conf);
appContext.getProto("movieLister", function(movieLister) {
//movieLister.movieFinder instanceof MovieFinder == true
//movieFinder.numMovies == 20
//movieFinder.includeShortFilms == true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment