Skip to content

Instantly share code, notes, and snippets.

@raganwald
Created October 22, 2012 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raganwald/3932975 to your computer and use it in GitHub Desktop.
Save raganwald/3932975 to your computer and use it in GitHub Desktop.
Discrepancy between CoffeeScript on Node and "Try CoffeeScript"
This CoffeeScript:
name = 'clyde'
do ->
"Hello #{name}" for name in ['algernon', 'sabine', 'rupert', 'theodora']
name
Complies to this on CoffeeScript under Node:
(function() {
var name, _i, _len, _ref;
name = 'clyde';
_ref = ['algernon', 'sabine', 'rupert', 'theodora'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
"Hello " + name;
}
name;
}).call(this);
And this on "Try CoffeeScript:"
var name;
name = 'clyde';
(function() {
var _i, _len, _ref, _results;
_ref = ['algernon', 'sabine', 'rupert', 'theodora'];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
_results.push("Hello " + name);
}
return _results;
})();
name;
Note that in the Node version, "name" is shadowed, but in the Try CoffeeScript version, it isn't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment