Why use typeof for identifying a function?

后端 未结 6 617
天涯浪人
天涯浪人 2020-12-09 13:03

Are there any significant reasons for using

typeof variable === \'function\'

versus

!!variable.call

for d

6条回答
  •  误落风尘
    2020-12-09 13:36

    A regular expression is a function

    /bar/("bar") === ["bar"]

    So typeof /bar/ === "function"

    Although only chrome recognises that a regexp literal can be used as a function. Whether this should be so or not is up for grabs. You can treat it just like a function!

提交回复
热议问题