JavaScript中使用Object.prototype.toString判断是否为数组
为什么要用Object.prototype.toString而不是Function.prototype.toString或者其它?这是和他们的toString解释方式有关系的。下面是ECMA中对Object.prototype.toString的解释:
Object.prototype.toString()
WhenthetoStringmethodiscalled,thefollowingstepsaretaken: 1.Getthe[[Class]]propertyofthisobject. 2.Computeastringvaluebyconcatenatingthethreestrings“[object“,Result(1),and“]”. 3.ReturnResult(2)