constructor vs typeof to detect type in JavaScript
问题 In this question I did not see suggestions to use constructor. So instead of typeof callback == "function" I would use callback && (callback.constructor==Function) . To me it seems obvious that comparison to memory pointers is always better than comparison to strings in terms of both runtime performance and coding safety. Why not use constructor to detect all types and forget about ugly typeof ? It works for all primitive types, functions and arrays: undefined === undefined null === null [1,2