constructor 属性
返回所有JavaScript 变量的构造器函数
"Bill".constructor // 返回 "function String() { [native code] }" (3.14).constructor // 返回 "function Number() { [native code] }" false.constructor // 返回 "function Boolean() { [native code] }" [1,2,3,4].constructor // 返回 "function Array() { [native code] }" {name:'Bill', age:62}.constructor // 返回" function Object() { [native code] }" new Date().constructor // 返回 "function Date() { [native code] }" function () {}.constructor // 返回 "function Function(){ [native code] }"
function isArray(myArray) { return myArray.constructor.toString().indexOf("Array") > -1; }
或者更简单,检查对象是否是数组函数
function isArray(myArray) { return myArray.constructor === Array; }