I thought I had figured out inheritance with JavaScript until this one threw me for a loop.
I have this SuperController as an AMD module:
define([
'underscore',
'#allCollections'
],
function ( _ , allCollections) {
function SuperController() {
}
SuperController.prototype = {
control: function (viewPath, viewOpts, routerOpts, cb) {
},
default: function (id) {
alert('controller has not yet implemented a default route.')
}
};
return new SuperController();
});
then I have a controller which I would like to inherit from the SuperController:
define(
[
'underscore',
'#allCollections',
'#allCSS',
'#SuperController'
],
function (_, allCollections, allCSS, SuperController) {
function Controller() {
}
Controller.prototype = {
jobs: function (id, changeViewCallback) {
var viewPath = 'app/js/jsx/relViews/jobs/jobsView';
var viewOpts = {};
viewOpts.id = id;
var routerOpts = {
useSidebar: true
};
SuperController.control(viewPath, viewOpts, routerOpts, changeViewCallback); // works!
this.control(viewPath, viewOpts, routerOpts, changeViewCallback); // does *not* work
},
default: function (id) {
console.log('default route implemented in controller.');
}
};
_.extend(Controller.prototype, SuperController.prototype);
return new Controller();
});
for some reason I can't this to work - the Controller doesn't have access to control in SuperController. The only way to get it to work is to just call SuperController.control() directly. Is there anything obvious that I am doing wrong?