posts - 12, comments - 4, trackbacks - 0, articles - 0

          FireBug 控制臺函數(shù)說明(轉(zhuǎn))

          Posted on 2007-11-01 10:17 Edward's 閱讀(264) 評論(0)  編輯  收藏 所屬分類: javascript

          FireBug 控制臺函數(shù)說明               

          原文地址:http://www.joehewitt.com/software/firebug/docs.php
          http://www.nirvanastudio.org/javascript/firebug-%E6%8E%A7%E5%88%B6%E5%8F%B0%E5%87%BD%E6%95%B0%E8%AF%B4%E6%98%8E.html

          FireBug 是一個非常實用的JavaScript以及DOM查看調(diào)試工具,是 Firefox 的一個插件。使用 FireBug 調(diào)試 AJAX 應(yīng)用非常方便,終于可以告別 alert 時代了!

          Console Logging 函數(shù)FireBug 為所有 Web 頁面提供了一個 console 對象。這個對象有以下函數(shù):
          Logging 基礎(chǔ)
          console.log("message" [,objects]) - 將一個字符串打印到控制臺。字符串可以包含任何“String Formatting”小節(jié)描述的模式。字符串后面的對象應(yīng)該用來取代之前字符串中的模式。(譯者注:大家用過C里面 printf 吧,效果基本是一樣的。)
          Logging 等級通常根據(jù)不同的等級來區(qū)分Logging的嚴(yán)重程度是很有幫助的。FireBug 提供了4個等級。為了達到視覺分離的效果,這些函數(shù)與 log 不同的地方就是它們在被調(diào)用的時候會自動包含一個指向代碼行數(shù)的鏈接。
          console.debug("message" [,objects]) - 記錄一個 debug 消息。
          console.info("message" [,objects]) - 記錄一個信息.
          console.warn("message" [,objects]) - 記錄一個警告.
          console.error("message" [,objects]) - 記錄一個錯誤.
          斷言斷言是一條確保代碼規(guī)則的非常好的途徑。console 對象包含了一系列各種類型的斷言函數(shù),并且允許你編寫自己的斷言函數(shù)。
          console.assert(a, "message" [,objects]) - Asserts that an a is true.
          console.assertEquals(a, b, "message" [,objects]) - Asserts that a is equal to b.
          console.assertNotEquals(a, b, "message" [,objects]) - Asserts that a is not equal to b.
          console.assertGreater(a, b, "message" [,objects]) - Asserts that a is greater than b.
          console.assertNotGreater(a, b, "message" [,objects]) - Asserts that a is not greater than b.
          console.assertLess(a, b, "message" [,objects]) - Asserts that a is less than b.
          console.assertNotLess(a, b, "message" [,objects]) - Asserts that a is not less than b.
          console.assertContains(a, b, "message" [,objects]) - Asserts that a is in the array b.
          console.assertNotContains(a, b, "message" [,objects]) - Asserts that a is not in the array b.
          console.assertTrue(a, "message" [,objects]) - Asserts that a is equal to true.
          console.assertFalse(a, "message" [,objects]) - Asserts that a is equal to false.
          console.assertNull(a, "message" [,objects]) - Asserts that a is equal to null.
          console.assertNotNull(a, "message" [,objects]) - Asserts that a is not equal to null.
          console.assertUndefined(a, "message" [,objects]) - Asserts that a is equal to undefined.
          console.assertNotUndefined(a, "message" [,objects]) - Asserts that a is not equal to undefined.
          console.assertInstanceOf(a, b, "message" [,objects]) - Asserts that a is an instance of type b.
          console.assertNotInstanceOf(a, b, "message" [,objects]) - Asserts that a is not an instance of type b.
          console.assertTypeOf(a, b, "message" [,objects]) - Asserts that the type of a is equal to the string b.
          console.assertNotTypeOf(a, b, "message" [,objects]) - Asserts that the type of a is not equal to the string b.
          測量(Measurement)下面的一些函數(shù)可以讓你方便的測量你的一些代碼。
          console.trace() - 記錄執(zhí)行點的堆棧信息。
          console.time("name") - 根據(jù) name 創(chuàng)建一個唯一的計時器。
          console.timeEnd("name") - 根據(jù) name 停止計時器,并且記錄消耗的時間,以毫秒為單位。
          console.count("name") - 記錄該行代碼執(zhí)行的次數(shù)。
          字符串格式化所有 console 的 logging 函數(shù)都可以通過以下模式格式化字符串:
          %s - 將對象格式化為字符串。
          %d, %i, %l, %f - 將對象格式化為數(shù)字。
          %o - 將對象格式化成一個指向 inspector 的超鏈接。
          %1.o, %2.0, etc.. - 將對象格式化成包含自己屬性的可交互的表格。
          %.o - 將對象格式化成具有自身屬性的一個數(shù)組。
          %x - 將對象格式化成一個可交互的 XML 樹形結(jié)構(gòu)。
          %1.x, %2.x, etc.. - 將對象格式化成一個可交互的 XML 數(shù)型結(jié)構(gòu),并且展開 n 層節(jié)點。
          如果你需要一個真實的 % 符號,你可以通過一個轉(zhuǎn)移符號就像這樣 "\%"。
          命令行函數(shù)內(nèi)建的命令行函數(shù)可以通過以下命令行使用:
          $("id") - document.getElementById() 的簡寫。(譯者注:跟 prototype.js 學(xué)來的吧?)
          $$("css") - 返回一個符合 CSS 選擇器的元素數(shù)組。
          $x("xpath") - 返回一個符合 XPath 選擇器的元素數(shù)組。
          $0 - 返回最近被檢查(inspected)的對象。
          $1 - 返回最近被檢查(inspected)的下一個對象。
          $n(5) - 返回最近被檢查的第n個對象。
          inspect(object) - 將對象顯示在 Inspector 中。
          dir(object) - 返回一個對象的屬性名數(shù)組。(譯者注:跟 Python 學(xué)的?)
          clear() - 清除控制臺信息。

          主站蜘蛛池模板: 汝阳县| 万盛区| 庄浪县| 广平县| 潼关县| 隆回县| 崇州市| 左权县| 阳江市| 斗六市| 桃园县| 绥阳县| 兰考县| 阿合奇县| 六安市| 西华县| 宁强县| 景宁| 宁蒗| 同仁县| 涞水县| 盖州市| 石楼县| 濮阳县| 博白县| 普定县| 青阳县| 互助| 阳山县| 临猗县| 平利县| 邛崃市| 土默特右旗| 建水县| 瑞昌市| 沿河| 隆化县| 随州市| 承德市| 浦城县| 自贡市|