In my last article here, I described how to make use of Mootools in a NodeJS applications. It included defining a class Application and then doing stuff with it. The class itself was defined in the same server.js file. This sometimes (very often for me) becomes a bottleneck as we start to work with one class per file approach. So, lets rewrite the program, create the file Application.js with following contents below
Application.js
So, now the main file contains the code as below
Server.js
Application.js
var Application = new Class(
{
Implements: [process.EventEmitter],
initialize: function()
{
console.log("App initialize");
},
compute: function()
{
console.log("App compute");
this.emit("done");
}
});
exports.Application = Application;
So, now the main file contains the code as below
Server.js
require('./mootools');
var _Application = require('./Application');
var app = new _Application.Application();
app.on("done", function() { console.log("App done"); });
app.compute();
No comments:
Post a Comment