4

Classes defined in 1 file does not appear to be available in other files. I tried declaring them like

class exports.Todo extends Backbone.Model ...
...
exports = exports ? this

But it appears in the compiled JS, exports is defined in the closure thus not available in other files anyways.

// Generated by CoffeeScript 1.3.3
(function() {
  var exports, ...

Whats the proper way to do this? I could use class window.Todo ... which appears to work ... but not really in my JS Test Driver ...

1

1 Answer 1

3

You've got two options; you can compile the coffeescript with the "join" option to concatenate all your coffee files before compiling, or you can do use exports similar to what you are doing. But it looks like - due to poor naming - the compiler is hoisting/lifting the exports variable assuming it is a local, which is wrong. See Export a class from a Coffeescript file on how to do it properly.

Keep in mind that what exports really point to depends on whether you intend to run your program in the browser, or under another environment such as node.js . The answer linked in above demonstrates a better way where you just call your "global environment" root, with code that sets it to whatever the environment believes is correct (exports under node.js, and this, meaning window, in the browser).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.