Wednesday, June 27, 2012

Working with Mootools & NodeJS - Second Approach

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
var Application = new Class(
    Implements: [process.EventEmitter],
    initialize: function()
        console.log("App initialize");
    compute: function()
        console.log("App compute");

exports.Application = Application;

So, now the main file contains the code as below
var _Application = require('./Application');

var app = new _Application.Application();
app.on("done", function() { console.log("App done"); });

No comments:

Post a Comment