JS中的箭头功能

问题描述 投票:-2回答:1

[请告知如何在JS中将下一个功能转换为箭头功能。该代码用于检查电子邮件验证。

function checkGmail() {
  let emailvalidation = document.getElementById('email').value;
  if (emailvalidation.length < 12) {
    document.getElementById('site-heading').style.color = "red";
  } else if (emailvalidation.indexOf('@gmail.com') == -1) {
    document.getElementById('site-heading').style.color = "red";
  } else if (emailvalidation.indexOf('.') < emailvalidation.length - 4) {

    document.getElementById('site-heading').style.color = "red";
  } else {
    document.getElementById('site-heading').style.color = "green";
  }
}
javascript arrow-functions
1个回答
0
投票

将其转换为箭头功能很简单,只需更改此:

function checkGmail() {
   // your code logic in here
}

to

const checkGmail = () => {
   // your code logic in here
}
© www.soinside.com 2019 - 2024. All rights reserved.