Created
February 17, 2014 11:24
-
-
Save gre/9048902 to your computer and use it in GitHub Desktop.
Real use-case for the advanced "fun.length" feature of JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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