Are functions objects or types in Javascript?

后端 未结 3 1019
无人及你
无人及你 2021-02-07 05:38

In his Eloquent Javascript, Haverbeke claims that (page 16):

\"In a JavaScript system, most of this data is neatly separated into things called va

3条回答
  •  不要未来只要你来
    2021-02-07 05:52

    They're a type of object.

    The typeof is "function":

    typeof (function() {}) === "function" // true
    

    The internal [[Class]] is [object Function]:

    ({}).toString.call(function() {}) === "[object Function]" // true
    

    They're an instance of the Function constructor prototype:

    (function(){}) instanceof Function // true
    

    They're an instance of the Object constructor prototype:

    (function(){}) instanceof Object // true
    

提交回复
热议问题