Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife.md
2023-01-06 00:37:55 +09:00

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")
)();