Skip to content Skip to sidebar Skip to footer

Underscore.js, Why Does `isfunction` Use `|| False`?

The optional override for isFunction(object) in Underscore.js (repo link to definition), reads as follows: // Optimize `isFunction` if appropriate. Work around some typeof bugs in

Solution 1:

See the issues covered in the comments, #1621, #1929 and #2236.

Shortly put, some platforms have a bug where typeof isn't a string unless you store it in a variable. The || false fixes the issue without introducing an extra variable.

Taken directly from #1621:

In IE8, with a variable everything works as expected:

var t = typeof obj
t === 'function'// false
t === 'object'// true

but without one, things are different:

(typeof obj) === 'function'// true, but SHOULD be false
(typeof obj) === 'object'// true

The extra check outlined above fixes the bug.

Post a Comment for "Underscore.js, Why Does `isfunction` Use `|| False`?"