An object type is registered differently in REPL than when executed

The other day I ran into a mysterious mistake. I have a simple program:

// file.coffee
C = require('./C')
console.log typeof C

// C.coffee
module.exports = ->
    val: true

When I import the code into node REPL, I see the following:

a = require('./file.js')
// 'function'

But when I started

// node ./file.js
// 'object'

Why is the type of object registered differently?

More importantly, since it is Cexported as a function, why is its type registered as an “object”?

+4
source share

Source: https://habr.com/ru/post/1629988/


All Articles