簡體   English   中英

CoffeeScript到NodeJS

[英]CoffeeScript to NodeJS

我目前正在嘗試將一些舊的CoffeeScript代碼通過(舊項目)移植到本機NodeJS。 我正在努力了解這到底在做什么? 或等效的節點?

  builder.macro_extensions = [
      'iced'
      'nsi'
      'txt'
  ]

  await exec """
    find #{temp} | grep #{(_.map @macro_extensions, (x) -> "-e '\\.#{x}'").join ' '}
  """, {silent:on}, defer e,r
  if e then return cb e

如果有人能指出我正確的方向,那將是完美的!

假設exec返回了一個Promise,代碼將2個參數傳遞給exec函數,等待返回的Promise被實現,然后將變量r為已解析的值。

如果發生任何錯誤(即,承諾被拒絕),它將變量e設置為該承諾的拒絕原因。

該代碼的JS等效項為:

builder.macro_extensions = ['iced', 'nsi', 'txt'];

const grepArgs = _.map(
  this.macro_extensions, // or maybe builder.macro_extensions
  x => ` -e '\\.${x}'`,
).join(''); // -e '\.iced' -e '\.nsi' -e '\.txt'

let r;
try {
  r = await exec(`find ${temp} | grep ${grepArgs}`, {silent: on});
} catch (e) {
  return cb(e);
}

// ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM