Skip to content

Instantly share code, notes, and snippets.

@rakeshpai
Created July 20, 2011 11:58
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 rakeshpai/1094831 to your computer and use it in GitHub Desktop.
Save rakeshpai/1094831 to your computer and use it in GitHub Desktop.
Variable shadowing in CoffeeScript, based on assignment scope
func = -> x = "some other string"
x = "some string"
func()
alert(x)
@rakeshpai
Copy link
Author

The compiled code. Note how x is redeclared inside the scope of the function.

var func, x;
func = function() {
  var x;
  return x = "some other string";
};
x = "some string";
func();
alert(x);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment