Skip to content

Instantly share code, notes, and snippets.

@hechien
Created July 4, 2011 03:18
Show Gist options
  • Save hechien/1062862 to your computer and use it in GitHub Desktop.
Save hechien/1062862 to your computer and use it in GitHub Desktop.
Make block as a function in JavaScript & Objective-C
var run_to_me = function(lonely){
if(lonely)
console.log("whenever you're lonely");
else
console.log("f**k off");
}
run_to_me(true);
run_to_me(false);
// BTW, "Run to me" is a song sang by Bee Gees.
void (^run_to_me)(BOOL) = ^(BOOL lonely){
if(lonely) NSLog(@"whenever you're lonely");
else NSLog(@"f**k off");
};
run_to_me(YES);
run_to_me(NO);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment