[英]jQuery's return value is Array, but constructor is Object. how?
例如,
$(document) // [ #document ] : document object in array
typeof $(document) // "object"
$(document).constructor // function Object() { [native code] } or function (a,b) { return some function; }
如果value是數組,則必須是Array構造函數。
它不是像對象一樣的數組。 因為像對象這樣的數組只有數組屬性,而不像[]。
怎么可能?
添加:如果可以,請顯示簡單的示例代碼。 喜歡
a = ...
console.log(a) // [ ... ]
console.log(a.constructor) // function Object or something
像[]
的數組也是JavaScript中的對象。 在JS中,大多數都是一個對象,例如函數,數組,文字對象,正則表達式......要真正知道你正在處理的是一個數組,你可以這樣做:
Object.prototype.toString.apply(myarray) === '[object Array]'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.