为什么Array instanceof Object?

adi*_*han 5 javascript

我正在玩instanceofjavascript,我偶然发现了以下内容.

Array instanceof Object
returns true

Object instanceof Array
returns false
Run Code Online (Sandbox Code Playgroud)

这里Array和Object之间有什么关系?

Jon*_*ski 8

在构造函数之间,关系或原型链是:

Array -> Function.prototype -> Object.prototype
Object -> Function.prototype -> Object.prototype
Run Code Online (Sandbox Code Playgroud)

第一个是true因为构造函数是一个Function,函数本身就是对象.

Array instanceof Function // true
Object instanceof Function // true

(function () {}) instanceof Object // true
Run Code Online (Sandbox Code Playgroud)