1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db2367417b2b2512b8b | Understand the Immediately Invoked Function Expression (IIFE) | 1 | 理解立即调用的函数表达式(IIFE) |
Description
(function(){请注意,该函数没有名称,也没有存储在变量中。函数表达式末尾的两个括号()会立即执行或调用它。此模式称为
console.log(“Chirp,chirp!”);
})(); //这是一个立即执行的匿名函数表达式
//输出“Chirp,chirp!”立即
immediately invoked function expression
或IIFE
。 Instructions
makeNest
并删除它的调用,所以它是一个匿名的immediately invoked function expression
( IIFE
)。 Tests
tests:
- text: 该功能应该是匿名的。
testString: 'assert(/\(\s*?function\s*?\(\s*?\)\s*?{/.test(code), "The function should be anonymous.");'
- text: 您的函数应在表达式的末尾加上括号以立即调用它。
testString: 'assert(/}\s*?\)\s*?\(\s*?\)/.test(code), "Your function should have parentheses at the end of the expression to call it immediately.");'
Challenge Seed
function makeNest() {
console.log("A cozy nest is ready");
}
makeNest();
Solution
// solution required