Thursday, June 28, 2012

Mootools Class in NodeJS global context - Second Approach

In my last article here, I described how to load Mootools class in NodeJS global context. What if I do not want to make use of include to load the class, is there a way I can still do it with require. So, lets rewrite the program, and check how to do it

Application.js
(function(){
 
var Application = this.Application = new Class(
{
    Implements: [process.EventEmitter],
    initialize: function()
    {
        console.log("App initialize");
    },
    compute: function()
    {
        console.log("App compute");
        this.emit("done");
    }
});
 
})();

So, now the main file contains the code as below

Server.js
require('./mootools');
require('./Application');
 
var app = new Application();
app.on("done", function() { console.log("App done"); });
app.compute();

Hope this will solve !

No comments:

Post a Comment