Question

I was poking around trying to figure a good way to do var, and here's one.. is this intentionally in cs, because it's not documented?

me=;

fetchUser()

  .then((_me) =>
    me = _me
    fetchFriend()
  )
  .then((_you) =>
    me.friend(_you)
  )
  .then(done)
  .otherwise(=>
    console.log ':('
  )

compiles correctly to

var me;

me = fetchUser().then((function(_this) {
  return function(_me) {
    me = _me;
    return fetchFriend();
  };
})(this)).then((function(_this) {
  return function(_you) {
    return me.friend(_you);
  };
})(this)).then(done).otherwise((function(_this) {
  return function() {
    return console.log(':(');
  };
})(this));

Edit: it's not compiling correctly.

I wouldn't expect me = fetchUser() either, but I didn't see that before https://github.com/jashkenas/coffee-script/issues/3098

Was it helpful?

Solution

I think it's just a quirk of the parser. The normal way variables are declared in order to establish scoping is just by defining them with some default value (e.g. null).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top