Last active
December 12, 2015 07:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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