In JavaScript, why typeof Function.prototype is “function”, not “object” like other prototype objects?

前端 未结 4 541
天涯浪人
天涯浪人 2020-11-27 07:05
console.log(typeof String.prototype); // object
console.log(typeof Number.prototype); // object
console.log(typeof Object.prototype); // object
console.log(typeof Bo         


        
4条回答
  •  醉话见心
    2020-11-27 07:58

    Because function is a native object which among other properties has internal [[Construct]] and [[Call]] properties and also explicit prototype property — the reference to a prototype of the future objects. And its class is function.

    F.[[Class]] = "Function"
    F.[[Call]] =  // function itself
    

    Thus [[Call]] besides the [[Class]] property (which equals to "Function") is the main in respect of objects distinguishing. Therefore the objects having internal [[Call]] property are called as functions. The typeof operator for such objects returns "function" value.

    see for reference

提交回复
热议问题