stitch icon indicating copy to clipboard operation
stitch copied to clipboard

Using 'this' instead of 'exports' doesn't seem to work

Open ManWithNoSpoon opened this issue 14 years ago • 1 comments

In node it's possible to use 'this' instead of 'exports' in a module. However, this does not seem to work when compiling with Stitch.

I've mad a configuration file in CoffeeScript that references a lot of its own values:

@DATA_SERVER_HOST = '192.168.0.1'
@DATA_SERVER_PORT = 8042
@DATA_SERVER_URL  = "http://#{@DATA_SERVER_HOST}:#{@DATA_SERVER_PORT}"

(Note that in CoffeeScript "@" is syntactic sugar for "this".)

To make this work with Stitch I instead have to write:

exports.DATA_SERVER_HOST = '192.168.0.1'
exports.DATA_SERVER_PORT = 8042
exports.DATA_SERVER_URL  = "http://#{exports.DATA_SERVER_HOST}:#{exports.DATA_SERVER_PORT}"

...which is slightly inconvenient.

Edit: I'm using Stitch 0.3.1 on Node.js 0.4.7

ManWithNoSpoon avatar Apr 29 '11 13:04 ManWithNoSpoon

this in a browser, outside of any context, is usually the DOM window so not a recommended practice

You could do something like this

config = ->
  @DATA_SERVER_HOST = '..'
  @DATA_SERVER_PORT = '..'
  this

module.exports = new config

mgutz avatar Jun 03 '11 00:06 mgutz