If you are using the “exports” object in your RequireJS module definition and happen to also be using CoffeeScript then be careful to either return the exports object at the end of the function or explicitly return nothing from the function by typing “return” on the last line. Like so:
define((require, exports, module) ->
exports.foo = 'bar'
return
)
If you don’t return nothing or the exports object CoffeeScript will compile this:
define((require, exports, module) ->
exports.foo = 'bar'
)
…to the following javascript:
define(function(require, exports, module) {
return exports.foo = 'bar';
});
Where the return value will be the string ‘bar’. This is no good because if you return a value from your module definition function, RequireJs uses it instead of the exports object. So when you come to require your module, you’ll be passed a String, rather than an object with a “foo” property as you’d expect.
I used to be able to find good advice from your blog posts.
Can I just say what a comfort to uncover an individual who really knows
what they are talking about on the web. You certainly know how to bring an issue to light and make it important.
A lot more people must check this out and understand this side of the story.
I can’t believe you aren’t more popular given that you certainly have the gift.
Hello! I’ve been following your site for some time now and finally got the
courage to go ahead and give you a shout out from Dallas Tx!
Just wanted to tell you keep up the excellent work!
Hello, every time i used to check webpage posts here early in the
morning, because i love to find out more and more.
Hello, yes this paragraph is really pleasant and I have learned lot of things from it
about blogging. thanks.
I’m extremely impressed with your writing skills and also with the layout on your weblog.
Is this a paid theme or did you modify it yourself? Either way keep up the
excellent quality writing, it’s rare to see a great blog like this one
today.