dpes8693 / frontend-mentor-program-1rd

前端培訓
0 stars 1 forks source link

詹珀柚_HW5&Question #43

Closed JamesChan0107 closed 2 months ago

JamesChan0107 commented 2 months ago

HW4:https://github.com/JamesChan0107/JamesChan0107.github.io/blob/main/HW4.md Question: 我發現我在寫script時,習慣寫成一長串且不愛設變數(ex.寫顯示鈕:document.getElementById('show').addEventListener('click',function(){document.getElementById('img').style.display = 'block';}),請問這習慣是否要去改?以及想了解依據您的經驗,哪些習慣要盡量培養,對未來coding有幫助呢?

dpes8693 commented 2 months ago
dpes8693 commented 2 months ago

HW4:https://github.com/JamesChan0107/JamesChan0107.github.io/blob/main/HW4.md Question: 我發現我在寫script時,習慣寫成一長串且不愛設變數(ex.寫顯示鈕:document.getElementById('show').addEventListener('click',function(){document.getElementById('img').style.display = 'block';}),請問這習慣是否要去改?以及想了解依據您的經驗,哪些習慣要盡量培養,對未來coding有幫助呢?

A1: 要改掉,因為有時候會移除元素 ex: 彈出視窗 document.getElementById() 不是每次都取的到DOM元素,抓不到會掛掉

A2: 入門的習慣培養:

其他可參考: https://www.standup-for-rights.work/post/q00003/