Skip to content

Instantly share code, notes, and snippets.

@hughrawlinson
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save hughrawlinson/e7a875c4a56e8696c4f8 to your computer and use it in GitHub Desktop.

Select an option

Save hughrawlinson/e7a875c4a56e8696c4f8 to your computer and use it in GitHub Desktop.
Function or variable, literally do not care.
// Is this a thing that people do? If so, what is it called? If not, why is it a bad idea? Answers on a tweet please. @hughrawlinson
var π = function(f,obj){
try{
f(obj());
}
catch(e){
f(obj);
}
};
var a = 1;
var b = function(){return 1};
π(function(arg){
console.log("Number: "+(arg+1));
},a);
π(function(arg){
console.log("Function: "+(arg+1));
},b);
// This function doesn't care if you've given it a value, or a function that returns a value
var updateBackgroundColor = function(color){
π(function(c){
// or however you update the background color
document.body.background.color = c;
},color);
}
// This works
var col = '#ffffff';
updateBackgroundColor(col);
// But so does this
updateBackgroundColor(goGetAColorFromSomeWeirdGenerativeProcessOrGetRequestOrSomewhereElseAndReturnItHere);
// where
goGetAColorFromSomeWeirdGenerativeProcessOrGetRequestOrSomewhereElseAndReturnItHere();
// is a function that returns a color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment