Last active
January 19, 2016 14:32
-
-
Save philmander/4422034 to your computer and use it in GitHub Desktop.
First inverted intro with no dependency injection
This file contains 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(["movies/json-movie-finder"], function(MovieFinder) { | |
var MovieLister = function() { | |
//hard coded dependency | |
this.movieFinder = new MovieFinder(); | |
}; | |
MovieLister.prototype.showMovies = function(query) { | |
var keywords = query.split(" "); | |
var movieResult = this.movieFinder.getMovies(keywords); | |
movieResult.done(function() { | |
movies.forEach(function(movie) { | |
console.log(movie.title); | |
}); | |
}); | |
}; | |
return MovieLister; | |
}); |
This file contains 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/json-movie-finder.js | |
define(["jsonp"], function(jsonP) { | |
var JsonMovieFinder = function() { | |
this.jsonpUrl = "http://jsonp.movies.com/movies"; | |
}; | |
JsonMovieFinder.prototype.getMovies = function(keywords) { | |
var result = jsonP.getJson(this.jsonUrl, { | |
keywords: keywords || "" | |
}); | |
return result; | |
}; | |
return JsonMovieFinder; | |
}); |
This file contains 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
// movie-app.js | |
require(["movies/movie-lister"], function(MovieLister) { | |
var movieLister = new MovieLister(); | |
movieLister.showMovies("thriller"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error in code:https://gist.github.com/philmander/4422034/#file-inverted-intro-1-2-js-L9
jsonUrl should be jsonpUrl