I have a class being used in node.js, and I want to pass various objects to this when requiring it.
Here’s the class:
var ItemHandler = (function() {
var items = new Array();
return {
start: function (item, callback) {
items.push(item);
ItemHandler.timer();
},
timer: function () {
var timer = setTimeout(function() {
console.log('test');
ItemHandler.timer();
}, 1000);
}
};
})();
module.exports = ItemHandler;
This is being called in one my routes, index.js. Like this:
var itemHandler = require('./lib/item.handler.js');
itemHandler.start(items);
What I would like to do is pass other objects being used in my route, to this file. Similar to this:
var itemHandler = require('./lib/item.handler.js')(socket)(res);
Here, I’d be passing in the socket object (returned from a socket.io connection and a response).
How would I structure my class to accept those two parameters?
Thanks a lot!
ItemHandleris now a function so…Or:
Hope it works, haven’t tested it 🙂