Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.4 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db2367417b2b2512b8b 了解立即调用函数表达IIFE 1 301328 understand-the-immediately-invoked-function-expression-iife

--description--

JavaScript 中的一个常见模式就是,函数在声明后立刻执行:

(function () {
  console.log("Chirp, chirp!");
})(); // 这是一个立即执行的匿名函数表达式
// 立即输出 "Chirp, chirp!"

请注意,函数没有名称,也不存储在变量中。函数表达式末尾的两个括号()导致它被立即执行或调用。这种模式被叫做自执行函数表达式或者IIFE

--instructions--

重写函数makeNest,并删除它的调用,取而代之是一个匿名的自执行函数表达式IIFE)。

--hints--

该函数应该是匿名的。

assert(/\((function|\(\))(=>|\(\)){/.test(code.replace(/\s/g, '')));

函数应该在表达式的末尾有括号,以便立即调用它。

assert(/}\)\(\)/.test(code.replace(/\s/g, '')));

--seed--

--seed-contents--

function makeNest() {
  console.log("A cozy nest is ready");
}

makeNest();

--solutions--

(function () {
  console.log("A cozy nest is ready");
})();

(function () {
  console.log("A cozy nest is ready");
}());

(() => {
  console.log("A cozy nest is ready");
})();

(() =>
  console.log("A cozy nest is ready")
)();