Các ghi đè tùy chọn cho isFunction(object)
trong Underscore.js (repo link to definition), đọc như sau:Underscore.js, tại sao `isFunction` sử dụng` || sai`?
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
// IE 11 (#1621), Safari 8 (#1929), and 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;
};
}
Những gì tôi là nhầm lẫn về là || false
, tại sao nó cần thiết sau một so sánh chuỗi? Vì typeof
luôn trả về một chuỗi nên không có sự mơ hồ?
Nhận xét nêu rõ sửa lỗi ghi đè một số lỗi typeof
, có trường hợp nào trên các nền tảng được liệt kê khi typeof
không trả lại chuỗi không?