Last active
December 10, 2015 10:38
-
-
Save philmander/4422282 to your computer and use it in GitHub Desktop.
Injecting a dependency as a constructor argument
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(movieFinder) { | |
| this.movieFinder = movieFinder; | |
| }; | |
| return MovieLister; | |
| }); | |
| //movies/movie-finder.js | |
| define(function() { | |
| var MovieFinder = function() { | |
| //constructor stuff | |
| }; | |
| return MovieFinder; | |
| }); |
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", | |
| args: [ | |
| "*movieFinder" | |
| ] | |
| }, | |
| 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 instanceof MovieLister == true | |
| //movieLister.movieFinder instanceof MovieFinder == true | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment