Created
December 31, 2012 20:18
-
-
Save philmander/4422436 to your computer and use it in GitHub Desktop.
Injecting literal values and dependencies as properties and methods
This file contains hidden or 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
| //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; | |
| }); |
This file contains hidden or 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
| //app-config.js | |
| define(function() { | |
| return { | |
| protos: { | |
| movieLister: { | |
| module: "movies/movie-lister", | |
| props: { | |
| movieFinder: "*movieFinder", | |
| includeShortFilms: true, | |
| setNumToShow: 20, | |
| } | |
| }, | |
| movieFinder: { | |
| module: "movies/movie-finder" | |
| } | |
| } | |
| }; | |
| }); |
This file contains hidden or 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
| 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