Skip to content

Instantly share code, notes, and snippets.

@Kasahs
Created September 9, 2015 15:54
Show Gist options
  • Save Kasahs/7bf56a7bbe0f19054435 to your computer and use it in GitHub Desktop.
Save Kasahs/7bf56a7bbe0f19054435 to your computer and use it in GitHub Desktop.
function foo(){
var callback = arguments[0] || function(){return "do nothing"};
var options = arguments[1] || {};
return [callback(), options.a || "no A", options.b || "no B", this];
}
// try these out to understand how to use apply and what it means to write functions which might be called in this way
foo(null, {a:1, b:2});
foo.apply("apples", [function(){return "do something"}, {a:1, b:2}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment