msloth / lgtv.js

Control LG WebOS TV using node.js
MIT License
249 stars 119 forks source link

Invoke functions without defining callbacks #12

Closed msloth closed 8 years ago

msloth commented 8 years ago

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.

hobbyquaker commented 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.

msloth commented 8 years ago

Cool, thanks! I'm still learning more than the basics of js.