If I compile this coffeescript to javascript using coffeescript compiler on my local machine:
window.App =
Models: {}
Views: {}
Collections: {}
Routers: {}
init: ->
Backbone.history.start()
I will end up with this generated javascript output:
// Generated by CoffeeScript 1.3.3
(function() {
window.App = {
Models: {},
Views: {},
Collections: {},
Routers: {}
};
({
init: function() {
var spotsList;
spotsList = new App.Views.SpotsList();
return Backbone.history.start();
}
});
}).call(this);
But, if I compile the same code in the online coffeescript to js http://js2coffee.org/ site I will get this result:
window.App = {
Models: {},
Views: {},
Collections: {},
Routers: {},
init: function() {
return Backbone.history.start();
}
};
The latter seems more expected. I think this may be causing some problems in my project, but can’t tell. I know that when I call App.init() my javascript console says it doesn’t exist. Thanks for the help!
FIXED!
As @Rob W pointed out below, I had some tabs in my coffeescript code. Later I figured out it was because I had a clean install of TextMate and didn’t have it set to “Soft Tabs (spaces)”.
There are two differences between your “local” and “online” result.
initmethod is dangling outsideApp.The extra closure is the default behaviour of the
coffeecompiler. Use the--bareflag to not get rid of the wrapper:There’s no reason for 2 to occur. Make sure that the spaces matches: If you’ve got four preceeding spaces before Models, etc, and three before init, then the output will be “wrong”.