javascript - Underscore.js, why does `isFunction` use `|| false`? -


the optional override isfunction(object) in underscore.js (repo link definition), reads follows:

// optimize `isfunction` if appropriate. work around typeof bugs in old v8, // ie 11 (#1621), safari 8 (#1929), , phantomjs (#2236). var nodelist = root.document && root.document.childnodes; if (typeof /./ != 'function' && typeof int8array != 'object' && typeof nodelist != 'function') {     _.isfunction = function(obj) {         return typeof obj == 'function' || false;     }; } 

what i'm confused || false, why necessary after string comparison? since typeof returns string there should no ambiguity?
comment states override fixes typeof bugs, there cases on listed platforms when typeof doesn't return string?

see issues covered in comments, #1621, #1929 , #2236.

shortly put, platforms have bug typeof isn't string unless store in variable.
|| false fixes issue without introducing variable.

taken directly #1621:

in ie8, variable works expected:

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

but without one, things different:

(typeof obj) === 'function' // true, should false (typeof obj) === 'object' // true 

the check outlined above fixes bug.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -