Skip to content

Instantly share code, notes, and snippets.

@romyilano
Last active August 29, 2015 14:11
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 romyilano/fc2b769321f8d9b05263 to your computer and use it in GitHub Desktop.
Save romyilano/fc2b769321f8d9b05263 to your computer and use it in GitHub Desktop.
javascript closures. they are like objective-c blocks but... theyre uh closures. they are 1st class functiona. do javascript people care about memory? this is shocking. hmmm.
/*
http://www.javascriptkit.com/javatutors/closures.shtml
closure is the local variables for a function - kept alive AFTER the function hs returned
closure is a stack-frame which is not deallocaed when the function returns
wait... what? javascript has malloc? i thought it was fluffy. they care about memory management?
just kidding
*/
function sayOriginators(originalPlaya) {
var shoutOutScrawl = 'people dont know where it started where it came from but ' +
originalPlayer + 'been here slaving and working and rocking since day one'; // need to learn how to flow i suck
var shoutOutAlert = function() { alert(shoutOutScrawl); }
return shoutOutAlert; // it's returning a fucntion ... so it's sort of like a block.
}
var bowDown1 = sayOriginators("Lady Saw");
bowDown1();
var bowDown2 = sayOriginators("The Sugar Hill Gang");
bowDown();
var bowDown3 = sayOriginators("Gregory Cylvester GC Coleman");
bowDown3();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment