Skip to content

Instantly share code, notes, and snippets.

@gre gre/lazy.js
Created Feb 17, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.