mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-24 15:01:04 -05:00
1.9 KiB
1.9 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 587d7db2367417b2b2512b8b | أدراك الوظائف المنفذة عند إعلانهم (Immediately Invoked Function Expression (IIFE)) | 1 | 301328 | understand-the-immediately-invoked-function-expression-iife |
--description--
النمط الشائع في JavaScript هو تنفيذ الوظيفة (function) بمجرد إعلانه:
(function () {
console.log("Chirp, chirp!");
})();
هذا اسمه تعبير غامض للوظيفة (anonymous function expression) الذي ينفذ على الفور، وينتج Chirp, chirp! على الفور.
لاحظ إن الوظيفة ليس لها اسم وليست مخزنة في متغير. ويؤدي القوسان () الواردان في نهاية ال function expression إلى تنفيذه أو استدعاءه على الفور. هذا النمط يعرف بـ immediately invoked function expression او IIFE.
--instructions--
أعد كتابة الوظيفة makeNest وأزيل استدعائها بحيث أنها تصبح anonymous immediately invoked function expression (IIFE).
--hints--
وينبغي أن يكون ال function مجهول اي anonymous.
assert(/\((function|\(\))(=>|\(\)){?/.test(code.replace(/\s/g, '')));
يجب أن يكون ال function الخاص بك بين قوسين في نهاية العبارة لاستدعائه على الفور.
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")
)();