Skip to content

Instantly share code, notes, and snippets.

@gre
Created February 17, 2014 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gre/9048902 to your computer and use it in GitHub Desktop.
Save gre/9048902 to your computer and use it in GitHub Desktop.
Real use-case for the advanced "fun.length" feature of JavaScript
function bindSomething (cb) {
anyEventSystem.on("something", function (e) {
if (cb.length === 0) {
cb();
}
else {
var computation = takesALotOfCPU();
cb(computation);
}
});
}
bindSomething(function (computation) {
console.log("something!", computation);
});
bindSomething(function () { // Nothing !
console.log("something!");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment