0

how can I implement something like this in coffee script? when I run node a.js both A and B is type function

a.js

exports = module.exports = A;
var B = require('./b');
function A() {
  console.log('I\'m A');
}
console.log('B=', typeof B);

b.js

exports = module.exports = B;
var A = require('./a');
function B() {
  console.log('I\'m B');
}
console.log('A=', typeof A);

I tried several approach in the Coffee-Script, but no one approach can do the exactly same like the javascript above.

1 Answer 1

1

Having modules depend on each other doesn't sound like a good idea, but if its what you need, this works:

a.coffee

A = () ->
  console.log('I\'m A')

module.exports = A

B = require('./b')

console.log('B=', typeof B)

b.coffee

B = () ->
  console.log('I\'m B')

module.exports = B

A = require('./a')

console.log('A=', typeof A)

Please make sure you read the module cycles section of the node.js documentation (it talks about how a module may not finish executing before returning).

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.