例如,jQuery的返回值是Array,但构造函数是Object。怎么样?
$(document) // [ #document ] : document object in array
typeof $(document) // "object"
$(document).constructor // function Object() { [native code] } or function (a,b) { return some function; }
如果值是数组,它必须是数组构造。
它不是像对象一样的数组。因为像对象这样的数组只有数组属性,不像[]。
这怎么可能?
add: 如果可以,请展示简单示例代码。 像
a = ...
console.log(a) // [ ... ]
console.log(a.constructor) // function Object or something
我不理解你为什么从$(document)返回“不是数组像对象”的推理 - 如果你看看实际的jQuery源代码,你会发现它是一个类似数组的对象和_不是一个数组... – nnnnnn 2012-07-09 06:07:38
@nnnnnn因为类似于数组的对象不显示为[] – Ephemera 2012-07-09 06:15:06
“显示”在哪里? '$(document)'的返回是'jQuery.fn.init'的一个实例,它已经添加了'0'和'length'属性。如果它是一个'Array',它会有像'.join()'这样的数组方法,但它不会。 _查看源代码._ – nnnnnn 2012-07-09 06:20:44