JavaScript的这段代码中()的含义是什么?

时间:2019-06-14 07:38:13

标签: javascript syntax async-await

我是JavaScript的新手。我在某处看到了以下代码,但不明白为什么在(之前有async而在此之后还有()?我知道JavaScript中的箭头功能,但似乎有些不同吗?

(async () => {
  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage();
  await page.goto(
    "http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=46741025610365786#",
    { waitUntil: "networkidle2" }
  );
  await page.click(".menu2 .violet", { button: "left" });
  await page.waitForSelector(".content .awesome", { timeout: 20000 });
  const data = await page.evaluate(() => {
    const trs = Array.from(document.querySelectorAll("#ClientTypeBody tr"));
    const arr = [];
    for (let i = 1; i < trs.length; i += 6) {
      arr.push(trs[i].innerText
          .replace(new RegExp("\t", "g"), ", ")
          .replace(new RegExp("حجم", "g"), "")
          .replace(/ \([^)]+\)/g, "")
          .replace(",", ""));
      arr.push('\n');
    }
    return arr.toString();
  });
  fs.writeFile("store.txt", data, err => {
    if (err) throw err;
    console.log("The file has been saved!");
  });
  await browser.close();
})();

此功能的输入/输出是什么? ?为什么async()的内部,并且前面还有空白的()

0 个答案:

没有答案