JavaScript (_.isFunction) code optimization

function, javascript, underscore.js

Solution

In some old versions of V8, regular expressions objects had a type of `"function"` (initially, regular expressions objects were callable as functions, even if nobody used that feature).

That's why it wasn't possible to use `typeof param === 'function'` to check if a value is a function.

This isn't the case now. Use `typeof`, not `_.isFunction`, this code is obsolete.

Problem

I needed to check an js object if is a function and i thought that this code should do it: `typeof param === 'function'` then i thought that checking with `_.isFunction` source code will be an good ideea. Underscore has the `if` below wrapped arround the above check, which i'm not sure what exactly does or mean. If someone can explain this would be great. Thanks ``` // Optimize `isFunction` if appropriate. if (typeof (/./) !== 'function') { .. } ```

Original source