Skip to content

Instantly share code, notes, and snippets.

@a-square
Last active December 12, 2015 07:19
Show Gist options
  • Save a-square/4736201 to your computer and use it in GitHub Desktop.
Save a-square/4736201 to your computer and use it in GitHub Desktop.
Why explicit shadowing is important. Many people wrongfully claim that the same problem arises with defines in Scheme. It doesn't.
$('.test').each (i, e) ->
e = $(e)
content = e.find('.content') # Gee, I hope it's not global!
e.find('.refresh').on 'click', (e) ->
$.ajax {
method: 'GET',
url: 'http://example.com',
type: 'text'
success: (res) -> content.html(res)
}
var x = 5;
function f(y) {
var x = 10; // not the same variable as x in the outer scope
return x + y;
}
console.log(f(10)); // 20
console.log(x); // 5
#lang r5rs
(define x 5)
(define (f y)
(define x 10)
(+ x y))
(display (f 10)) ; => 20
(newline)
(display x) ; => 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment