Last active
August 29, 2015 14:02
-
-
Save djsmith42/031da4151807ccb25d7e to your computer and use it in GitHub Desktop.
This file contains 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
function counter() { | |
var n = 0; | |
return function() { | |
n++; | |
return n; | |
} | |
} | |
c = counter(); | |
c(); // ouputs 1 | |
c(); // outputs 2 | |
$("button").click(function(event) { | |
// handle the click | |
} | |
var handlers = [ | |
function() { ... }, | |
function() { ... } | |
]; | |
var thingsToRun = { | |
red: function() { ... }, | |
blue: function() { ... }, | |
green : function() { ... } | |
} | |
(function () { | |
var name = "Bob, the Closure String"; | |
$("button").click(function() { | |
alert("My closure has a first name. It's " + name) | |
}); | |
})(); | |
function capitalize(list) { | |
for (var i=0; i<list.length; i++) { | |
list[i] = list[i].toUpperCase(); | |
} | |
} | |
function upper(str) { | |
return str.toUpperCase(); | |
} | |
function capitalize(list) { | |
return list.map(upper) | |
} | |
lowerCase(underscore(capitalize(['foo', 'bar']))) | |
$.get("http://example.com") | |
.then(doSomething) | |
.then(doSomethingElse) | |
.then(andFinish) | |
function findNextPrime(start) { | |
// do lots of work | |
return nextPrime; | |
} | |
function findNextPrime(start) { | |
return function() { | |
// do lots of work | |
return nextPrime; | |
} | |
} | |
translated_string = trans("Hello, world!") | |
function Thing() { | |
this.name = "Bob"; | |
this.age = 42; | |
} | |
var thing = new Thing(); | |
var x = {name: "Bob"}; | |
x.name = "Fred"; // Not allowed! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment