久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是什么讓 Firebug/Chrome 控制臺將自定義對象視為數

What makes Firebug/Chrome console treat a custom object as an array?(是什么讓 Firebug/Chrome 控制臺將自定義對象視為數組?)
本文介紹了是什么讓 Firebug/Chrome 控制臺將自定義對象視為數組?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

當我使用 jQuery 進行開發時,我經常發現自己在 Chrome/Firebug 控制臺中輸入選擇器并查看它們給我的信息.它們的格式總是很好,就好像它們是數組一樣:

When I am developing in jQuery, I frequently find myself typing selectors into the Chrome/Firebug console and seeing what they give me. They are always nicely formatted as if they were arrays:

我正在嘗試弄清楚是什么使控制臺將對象視為數組.例如,以下自定義對象不被視為數組:

I am trying to work out what it is that makes the console treat an object as an array. For instance, the following custom object is not treated as an array:

function ElementWrapper(id) {
    this[0] = document.getElementById(id);
}

如果我隨后添加一個 length 屬性和一個 splice 方法,它會神奇地作為一個數組工作,任何帶有整數鍵的屬性都被視為數組的成員:

If I then add a length property and a splice method, it magically works as an array, with any properties with integer keys treated as members of the arrays:

function ElementWrapper(id) {
    this[0] = document.getElementById(id);
    this.length = 1;
    this.splice = Array.prototype.splice;
}

所以本質上我的問題是:是什么決定了控制臺是否將對象顯示為數組?是否有任何理由,或者它是完全任意的如果一個對象具有這些屬性,它必須是一個數組?"如果有,決定性的屬性是什么?

So essentially my question is: what determines whether the console displays an object as an array? Is there any rationale to it, or is it a completely arbitrary "if an object has these properties, it must be an array?" If so, what are the decisive properties?

推薦答案

這就是 Firebug 的 isArray 方法的作用:(來自 Firebug 源碼)

This is what Firebug's isArray method does: (from the Firebug source)

if (!obj)
    return false;
else if (isIE && !isFunction(obj) && typeof obj == "object" && isFinite(obj.length) && obj.nodeType != 8)
    return true;
else if (isFinite(obj.length) && isFunction(obj.splice))
    return true;
else if (isFinite(obj.length) && isFunction(obj.callee)) // arguments
    return true;
else if (instanceOf(obj, "HTMLCollection"))
    return true;
else if (instanceOf(obj, "NodeList"))
    return true;
else
    return false;

當然,這些檢查都不能確保對象是真正的 JavaScript 數組,但它們可以合理地猜測對象是否是偽數組,這反過來又為您提供了一種方便的類似數組的表示來進行調試.

Of course, none of these checks ensures that the object is a true JavaScript array, but they do a reasonable job of guessing whether an object is a pseudo-array, which in turn gives you a convenient array-like representation for debugging.

Chrome 可能會也可能不會使用這些相同的檢查,并且 Firefox 4 中的新 Web 控制臺不會將除真正數組之外的任何內容識別為數組.

Chrome may or may not use these same checks, and the new Web Console in Firefox 4 doesn't recognize anything other than true arrays as arrays.

這篇關于是什么讓 Firebug/Chrome 控制臺將自定義對象視為數組?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 日韩在线免费视频 | 日韩在线国产 | 国产精品免费一区二区三区 | 99热99| 日本a网站 | 不卡一区 | www.日韩 | 亚洲嫩草| 在线欧美一区二区 | 龙珠z国语版在线观看 | 激情久久av一区av二区av三区 | 九九av| 青青草在线视频免费观看 | 亚洲高清视频在线观看 | 亚洲精品一二区 | 北条麻妃一区二区三区在线观看 | 亚洲精品福利视频 | 国产视频第一页 | 欧美日韩免费视频 | 99视频 | 草久久| 亚洲精品国产电影 | 亚洲国产自产 | 日日日色 | 久久精品亚洲精品 | 国产一区二区美女 | 午夜男人免费视频 | 在线日韩 | 中文字幕一区在线观看视频 | 日韩成人免费视频 | 久久精品国产99国产精品亚洲 | 国产成人精品视频 | 国产精品福利网站 | 亚洲日韩中文字幕一区 | 一区二区日韩 | 免费的黄色片子 | 国产精品成人品 | 国产一区二区三区日韩 | 成人精品一区 | 一区二区三区影院 | 国产高清视频在线观看 |