检查函数是否属于 javascript 中的 Function 类型

Checking if a function is of type Function in javascript

是的,我知道有很多关于这个的帖子,但我不明白 this post 的选择答案。特别是,为什么需要 return object?

为什么像 Object.prototype.toString.call(myFunc) 这样的东西不能像 MDN 描述的那样足够?

why is it necessary to return object?

没有必要执行 object &&,但这是避免对 null 等值进行方法调用的虚假值的快捷方式。当然,如果您正在寻找速度,您可能应该选择 typeof object == "function"

Why wouldn't something like Object.prototype.toString.call(myFunc) be sufficient?

足够了。

return object && getClass.call(object) == '[object Function]'

这个结构简单地验证 object 是否不是 nullundefined(通常是假的)。
这样它会更快,因为 JavaScript 不会评估 getClass() 对虚假 object 的调用。