On Feb 17, 8:53 pm, "Dmitry A. Soshnikov" <[email protected]> wrote: [...] > It to omit initial example, but instead to take a some common abstract, > the last case with a function is useful for me. E.g. > > function foo(callback) { > /* stuff */ > callback && callback(data); > } > > or even: > > function foo(callback) { > /* stuff */ > typeof callback == "function" && callback(data); > }
I think the first is preferable for a number of reasons. Robustly determining if something is callable is a much more difficult than it seems, I don't think it can be done in a general case. E.g. callable host objects do not necessarily return 'function' or even 'object' when tested with typeof. The best solution may be to specify in documentation that the passed value must be a reference to a callable object, then in the function if something has been passed, call it (i.e. per the first example above). "isFunction (Code Worth Recommending Project)" <URL: http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/13b14565817a35ba?tvc=2&q=isCallable+function > "When is a function not a function?" <URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/792457773ca7cf01/0d769b851b3a0a6f?lnk=gst&q=isCallable+function#0d769b851b3a0a6f > -- Rob -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
