Every object has a toString() method that is automatically called when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected. By default, the toString()method is inherited by every object descended from Object. If this method is not overridden in a custom object,toString() returns “[object type]”, where type is the object type.
So in order to tell arrays from pure objects, Object.prototype.toString() is the one we need.
啊,JS 真是一门复杂的语言,判断个变量类型还得先略懂最艰深的核心概念才能行:
较为浅显易懂的一篇: Why Object.prototype.toString.call()?
更古老但也更有深度的一篇:Fixing the JavaScript typeof operator – JavaScript, JavaScript…