[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
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#