Created
December 31, 2012 20:48
-
-
Save philmander/4422634 to your computer and use it in GitHub Desktop.
Creating a prototypal inheritance chain with the Inverted
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(function() { | |
var JsonMovieFinder = function(jsonpUrl) { | |
this.jsonpUrl = jsonpUrl; | |
}; | |
return JsonMovieFinder; | |
}); | |
//movies/base-movie-finder.js | |
define(function() { | |
var BaseMovieFinder = function() { | |
this.maxMoviesToFind = 100; | |
}; | |
return BaseMovieFinder; | |
}); | |
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
//app-config.js | |
define(function() { | |
return { | |
protos: { | |
jsonMovieFinder: { | |
module: "movies/json-movie-finder", | |
args: [ "http://movies.com/movies.json" ], | |
extendsRef: "baseMovieFinder" | |
}, | |
baseMovieFinder: { | |
module: "movies/base-movie-finder", | |
props: { | |
maxMoviesToFind: 50 | |
} | |
} | |
} | |
}; | |
}); |
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
require(["inverted", "app-config"], function(inverted, conf) { | |
var appContext = inverted.create(conf); | |
appContext.getProto("jsonMovieFinder", function(movieFinder) { | |
//movieFinder instanceof BaseMovieFinder == true | |
//movieFinder instanceof JsonMovieFinder == true | |
//(movieFinder.constructo == JsonMovieFinder) == true | |
//(movieFinder.maxMoviesToFind == 50) == true | |
//(movieFinder.jsonpUrl == "http://movies.com/movies.json") == true | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment