I am trying to implement some functionality into a NodeJS application where some of my controllers (modules) will inherit from one bass module in order to store all common functionality in there. I am having difficulty doing this though and I am unsure why.
Here is what I have so far:
My base module (from which others will inherit from):
var http = require('http');
function ApiBaseController() {
var self = this;
}
ApiBaseController.prototype.makeRequest = function() {
};
module.exports = ApiBaseController;
A child module (that will inherit from the one above:
var APIBaseController = require(__dirname + '/apiBase/ApiBaseController.js'),
inherits = require('util').inherits;
function JustGivingAPI() {
APIBaseController.apply(this);
}
inherits(APIBaseController, JustGivingAPI);
JustGivingAPI.prototype.getAmount = function() {
console.log("here");
};
module.exports = JustGivingAPI;
And the client code which requires the module:
var express = require('express');
var router = express.Router();
var JustGivingController = require('../controllers/api/JustGivingAPI');
var APIObject = new JustGivingControllerObject();
I am trying to implement the aply Javascript method from within the JustGivingAPI module's constructor to inherit the parent module's methods but they don't appear in the returned module. Can anyone advise me as to where I have gone wrong and if this is a good idea or not?
thanks!