[RequireJS] Using exports in CoffeeScript modules
If you use RequireJS with exports in CoffeeScript, make sure the last line of your file is not:
exports = MyModule
OR
exports.Foo = Foo
Since CoffeeScript has implicit returns, that will get compiled down to:
return exports = MyModule
AND
return exports.Foo = Foo
This will sometimes result in situations where requiring that module will give you an empty object {}.
To fix this you can either:
1) Just use explicit return and avoid using exports.
2) Put and empty return at the end of your module.
Written by Jack Hsu
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#