Closed msloth closed 8 years ago
i don't think this is neccessary, can't imagine that above example throws an exception if fn
is undefined
.
typeof undefined
simply returns undefined
, and (typeof fn === 'function')
is a widely used pattern for optional callbacks and totally ok.
Cool, thanks! I'm still learning more than the basics of js.
In many/most/some/a few at least of the functions, a callback is expected. The code looks like this:
if (typeof fn === 'function') {
which makes it break if no callback is defined. Now one is forced to use empty callbacks which clutters up etc.Replace the instances of the above code with
if (fn && typeof(fn) === 'function') {
to allow invoking functions without defining callbacks.