I'm writing a simple app that uses John Resig's simple class inheritance. I'm doing this in Node.js and I'm also using CoffeeScript. I was trying to write CoffeeScript that would output code similar to this file in the BrowserQuest game.
When I write CoffeeScript like this, though:
cls = require './class'
module.exports = Model = cls.Class.extend({
init: () ->
console.log 'Model.init()'
})
The "var" is automatically added to Model, so it doesn't seem to be exported properly.
var Model, cls;
cls = require('../class');
module.exports = Model = cls.Class.extend({
init: function() {
return console.log('Model.init()');
}
});
Is there a way to mark a variable to not use "var" with CoffeeScript?
Every variable is defined with a var on CoffeeScript unless it's given a scope:
cls = require './class'
module.exports = GLOBAL.Model = cls.Class.extend({
init: () ->
console.log 'Model.init()'
})
compiles to:
var cls;
cls = require('./class');
module.exports = GLOBAL.Model = cls.Class.extend({
init: function() {
return console.log('Model.init()');
}
});
I've used GLOBAL as an example, but you can use any scope.