Object and Function are quite confusing

前端 未结 7 1772
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 03:47
Object instanceof Object
true
Object instanceof Function
true
Function instanceof Object
true
Function instanceof Function
true

so if Function is a

相关标签:
7条回答
  • 2020-12-10 04:36

    I think this is more due to the unique way in which objects are defined. You don't define a type in javascript, you define a constructor. But you also do not define the constructor as a constructor, it's simply a function.

    You can then refer to the types by the name of their constructor....which is just a function.

    function Tiger(){ //function, or object?
    }
    
    function Apple(){ //function, or object?
    }
    

    Both could be objects, or perhaps just functions. Only the way you use them will determine that. So it kind of makes sense that at a low level, objects are functions and functions are objects, but there is still a difference, right?

    0 讨论(0)
提交回复
热议问题