日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
熟練掌握J(rèn)Sconsole.log,拯救你的代碼

來源:Pexels JS Console

做網(wǎng)站、成都網(wǎng)站建設(shè)介紹好的網(wǎng)站是理念、設(shè)計和技術(shù)的結(jié)合。成都創(chuàng)新互聯(lián)公司擁有的網(wǎng)站設(shè)計理念、多方位的設(shè)計風(fēng)格、經(jīng)驗豐富的設(shè)計團(tuán)隊。提供PC端+手機(jī)端網(wǎng)站建設(shè),用營銷思維進(jìn)行網(wǎng)站設(shè)計、采用先進(jìn)技術(shù)開源代碼、注重用戶體驗與SEO基礎(chǔ),將技術(shù)與創(chuàng)意整合到網(wǎng)站之中,以契合客戶的方式做到創(chuàng)意性的視覺化效果。

調(diào)試就如同在犯罪電影中同時扮演偵探和兇手。

——Filipe Fortes

大多數(shù)的開發(fā)人員喜歡在瀏覽器中輸出信息以更多地了解問題。筆者應(yīng)該不是唯一一個這樣做的。

在瀏覽器控制臺中輸出信息對開發(fā)人員來說就像一次拯救行動。在代碼調(diào)試中遇到種種疑難雜癥時,Console.log()就像靈丹妙藥。

其實,除了最常用的Console.log()語句,還有其他簡化調(diào)試過程的方式。

接下來,小芯將通過例子逐個介紹它們。

1. console.assert()

只想輸出選定日志時這一指令非常實用,它將只輸出錯誤參數(shù),如果第一個參數(shù)正確,它就不起作用。

斷言(assertion)

2. console.group() & console.groupEnd( )

可以使用控制臺將消息分組。

將消息分組

3. console.trace()

該方法會追蹤并顯示代碼在何時終止運行。

追蹤

來源:Pexels JS Console

4. console.count()

該函數(shù)記錄count()函數(shù)的調(diào)用次數(shù),有一個可選的參數(shù)label。

如果調(diào)用時提供了label,該函數(shù)將記錄使用該特定label調(diào)用count()的次數(shù)。

如果調(diào)用時省略label,函數(shù)將記錄在這一行調(diào)用count()的次數(shù)。

計數(shù)

5. console.table ()

希望看到合適易讀的JSON文本嗎?

對數(shù)組進(jìn)行更好的可視化處理!

6. 在控制臺消息中添加樣式

所有控制臺消息看起來都一樣嗎?現(xiàn)在就不一樣了,讓調(diào)試日志中重要的部分看起來更加醒目。

帶顏色的消息

可以通過以下方式改變?nèi)罩局刑囟▎卧~的顏色:

高亮顯示特定單詞

7. console.time()

console.time()用于跟蹤操作耗時,它是跟蹤JavaScript執(zhí)行所耗費的短暫時間的好方法。

8. 控制臺中的HTML

從控制臺中獲取HTML元素,跟檢查元素的方式相同。

HTNL元素展示

9. console.dir()

輸出指定對象的JSON形式。

10. console.memory( )

想知道Javascript應(yīng)用占用了多少瀏覽器內(nèi)存?

內(nèi)存

來源:Pexels JS Console

11. 使用占位符

各種不同的占位符如下所示:

  • %o :接受一個對象,
  • %s :接受一個字符串
  • %d :接受一個小數(shù)或整數(shù)

占位符介紹

12. console.log() | info( ) | debug( ) | warn( ) | error( )

這些語句將根據(jù)事件的類型用不同顏色標(biāo)識原始字符串。

console log/info/debug/warn/error

13. console.clear( )

最后但也很重要的一點是,使用clear()命令清除所有控制臺消息。

以下是要點補(bǔ)充。

https://gist.github.com/Harshmakadia/fc25e56cb8f49145f4c9b3528f04215f

 
 
 
 
  1. // time and time end 
  2. console.time("This"); 
  3. let total =0; 
  4. for (let j =0; j <10000; j++) { 
  5. total += j 
  6. console.log("Result", total); 
  7. console.timeEnd("This"); 
  8. // Memory 
  9. console.memory() 
  10. // Assertion 
  11. consterrorMsg='Hey! The number is not even'; 
  12. for (let number =2; number <=5; number +=1) { 
  13. console.assert(number %2===0, {number: number, errorMsg: errorMsg}); 
  14. // Count 
  15. for (let i =0; i <11; i++) { 
  16. console.count(); 
  17. // group & groupEnd 
  18. console.group(); 
  19. console.log('Test message'); 
  20. console.group(); 
  21. console.log('Another message'); 
  22. console.log('Something else'); 
  23. console.groupEnd(); 
  24. console.groupEnd(); 
  25. // Table 
  26. constitems= [ 
  27. name:"chair", 
  28. inventory:5, 
  29. unitPrice:45.99 
  30. }, 
  31. name:"table", 
  32. inventory:10, 
  33. unitPrice:123.75 
  34. }, 
  35. name:"sofa", 
  36. inventory:2, 
  37. unitPrice:399.50 
  38. ]; 
  39. console.table(items) 
  40. // Clear 
  41. console.clear() 
  42. // HTML Element 
  43. let element =document.getElementsByTagName("BODY")[0]; 
  44. console.log(element) 
  45. // Dir 
  46. constuserInfo= {"name":"John Miller", "id":2522, "theme":"dark"} 
  47. console.dir(userInfo); 
  48. // Color 
  49. console.log('%cColor of the text is green plus small font size', 'color: green; font-size: x-small'); 
  50. // pass object, variable 
  51. constuserDetails= {"name":"John Miller", "id":2522, "theme":"dark"} 
  52. console.log("Hey %s, here is your details %o in form of object", "John", userDetails); 
  53. // Default 
  54. console.log('console.log'); 
  55. console.info('console.info'); 
  56. console.debug('console.debug'); 
  57. console.warn('console.warn'); 
  58. console.error('console.error'); 

網(wǎng)頁標(biāo)題:熟練掌握J(rèn)Sconsole.log,拯救你的代碼
路徑分享:http://www.5511xx.com/article/dhgcohe.html