Clean coding in JavaScript
리팩토링 자바스크립트, 클린 코드 작성하기
Using the map function
before
const myList = list => {
const newList = []
for (let i = 0; list.length; i++) {
newList[i] = list[i] * 2
}
return newList
}
after
const myList = list => list.map(x => x * 2)
Avoid callback hell with async/await
before
const sendToEmail = () => {
getIssue().then(issue => {
getOwner(issue.ownerId).then(owner => {
sendEmail(owner.email, `some text ${issue.number}`).then(() => {
console.log("email successfully")
})
})
})
}
after
const sendToEmail = async () => {
const issue = await getIssue()
const owner = await getOwner(issue.ownerId)
const email = await sendEmail(owner.emaill, `some text ${issue.number}`)
console.log("email successfully")
}
'JS' 카테고리의 다른 글
JS Module (0) | 2020.09.23 |
---|---|
Refactoring javascript 2 (0) | 2020.09.23 |
Detect Dark mode in CSS & Javascript (0) | 2020.09.23 |
Javascript 삼각함수 sin, cos, tan (0) | 2020.09.22 |
javascript find (0) | 2020.09.21 |
댓글