Blog Posts

No results for undefinedPowered by Algolia

DailyLog

Refactoring javascript 1

September 08, 2020

Photo by Florian Krumm on Unsplash

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")
}

Refactoring javascript 2

Refactoring javascript 2 Read >