例如,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