Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

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

Open
ManWithNoSpoon opened this issue Apr 29, 2011 · 1 comment
Open

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

ManWithNoSpoon opened this issue Apr 29, 2011 · 1 comment

Comments

@ManWithNoSpoon
Copy link

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

@mgutz
Copy link

mgutz commented Jun 3, 2011

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants