Skip to content

Instantly share code, notes, and snippets.

@philmander
Created December 31, 2012 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philmander/4422634 to your computer and use it in GitHub Desktop.
Save philmander/4422634 to your computer and use it in GitHub Desktop.
Creating a prototypal inheritance chain with the Inverted
//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;
});
//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
}
}
}
};
});
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