I am working on a combination of coffeescript and require.js for AMD.
The problem would be that I must return a value for each module loaded by require.js, and I do that. But.. coffeescript helps me out and appends:(function() { and }).call(this);. which blows my code.
main.js
require.config( {
paths: {
'backbone': 'libs/AMDbackbone-0.5.3',
'underscore': 'libs/underscore-1.2.2',
'text': 'libs/require/text',
'jquery': 'libs/jquery-1.7.1',
},
baseUrl: '/app'
} );
require(
['require', 'backbone', 'jquery', 'underscore' ],
function( require, Backbone, $, _ ) {
// framework loaded
require(
['require', 'app'],
function( require, app) {
return {};
} );
} );
app.js
define( [
'jquery',
'underscore',
'backbone',
'views/gameview',
], function( $, _, Backbone, GameView, ) {
"use strict";
window.app = {};
$(function(){
var app = window.app = _.extend({
views: {
GameView: new GameView
},
//code..
}, window.app);
//code...
return window.app;
} );
And the coffeescript:
/views/gameview.coffee
define ["jquery", "underscore", "backbone"], ($, _, Backbone, RankView) ->
"use strict"
GameView = Backbone.View.extend()
GameView
Which translates to:
/views/gameview.js
(function() {
define(["jquery", "underscore", "backbone"], function($, _, Backbone) {
"use strict";
var GameView;
GameView = Backbone.View.extend({...});
return GameView;
});
}).call(this);
But I would like to translate to:
define(["jquery", "underscore", "backbone"], function($, _, Backbone) {
"use strict";
var GameView;
GameView = Backbone.View.extend({...});
return GameView;
});
Would be nice to use this in console: var GameView = new app.views.GameView; in console.
How do I force coffeescript compiler not to do that? Is there a flag or something for that?
AGAIN: I JUST WANT TO CUT OFF (function() { and }).call(this); – is not that important the amd code behind it, be it global or not..
Thank you
You can use the
--bareflag when compiling your coffee files: