Skip to content

Instantly share code, notes, and snippets.

@pedromcunha
Created July 30, 2014 03:05
Show Gist options
  • Save pedromcunha/2dd37cfee80790b1572a to your computer and use it in GitHub Desktop.
Save pedromcunha/2dd37cfee80790b1572a to your computer and use it in GitHub Desktop.
Function Expressions and Instant Invocations.
var listOfSharks = ["Sea Pain", "Great Wheezy",
"DJ Chewie", "Lil' Bitey",
"Finmaster Flex", "Swim Khalifa",
"Ice Teeth", "The Notorious J.A.W."];
var listOfTargets = ["icicle bat", "snow yeti",
"killer penguin", "frost tiger",
"polar bear", "iceberg",
"blue witch", "wooly mammoth"];
function makeTargetAssigner( sharks, targets ){
return function (shark) {
var target = '';
for (var i = 0; i < sharks.length;i++) {
if (sharks[i] == shark) {
target = targets[i];
}
}
alert(
"What up, "+shark+"!\n" +
"There've been "+target+" sightings in our 'hood!\n" +
"Time for a swim-by lasering, homie!");
};
}
var getTargetFor = makeTargetAssigner(listOfSharks, listOfTargets);
getTargetFor("Ice Teeth");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment