×ðÁú¿­Ê±¹ÙÍøµÇ¼

jsÖÐʲôÊDZհüº¯Êý

±Õ°üº¯ÊýÊÇÓµÓÐ×ÔÓɱäÁ¿£¬×ÝÈ»ÔÚ½¨ÉèËüµÄÉÏÏÂÎÄ¿¢Êºó£¬ÈÔÈ»¿ÉÒÔ»á¼ûÍⲿÉùÃ÷±äÁ¿µÄº¯Êý¡£ÆäÔ­ÀíÊÇ£ºÄÚ²¿º¯Êý¿ÉÒÔ»á¼ûÍⲿº¯ÊýµÄ×÷ÓÃÓò±äÁ¿¡£±Õ°üº¯Êý½¨Éè×Ô¼ºµÄ´Ê·¨ÇéÐΣ¬ÆäÖаüÀ¨Íⲿº¯ÊýµÄ×÷ÓÃÓò±äÁ¿¡£±Õ°üº¯Êý¿ÉÒÔ»á¼ûÆä´Ê·¨ÇéÐÎÖÐÉúÑĵÄ×ÔÓɱäÁ¿£¬×ÝÈ»Íⲿº¯ÊýÒÑÖ´ÐÐÍê±Ï¡£

ʲôÊDZհüº¯Êý£¿

ÔÚ JavaScript ÖУ¬±Õ°üº¯ÊýÊÇÒ»¸öÓµÓÐ×ÔÓɱäÁ¿µÄº¯Êý£¬×ÔÓɱäÁ¿ÊÇÖ¸ÔÚº¯ÊýÍⲿÉùÃ÷µÄ±äÁ¿¡£×ÝÈ»ÔÚ½¨ÉèËüµÄÉÏÏÂÎÄ¿¢Êºó£¬ËüÈÔÈ»¿ÉÒÔ»á¼ûÕâЩ±äÁ¿¡£

±Õ°üº¯ÊýµÄÔ­Àí

±Õ°üº¯ÊýµÄÊÂÇéÔ­ÀíÈçÏ£º

JavaScript µÄ×÷ÓÃÓò¹æÔòÔÊÐíÄÚ²¿º¯Êý»á¼ûÍⲿº¯ÊýµÄ×÷ÓÃÓò¡£

±Õ°üº¯ÊýÔÚ±»Ö´ÐÐʱ£¬»á½¨ÉèÆä×Ô¼ºµÄ´Ê·¨ÇéÐΣ¬ÆäÖаüÀ¨Íⲿº¯ÊýµÄ×÷ÓÃÓò±äÁ¿¡£

×ÝÈ»Íⲿº¯ÊýÒѾ­Ö´ÐÐÍê±Ï£¬±Õ°üº¯ÊýÈÔÈ»¿ÉÒÔ»á¼ûÆä´Ê·¨ÇéÐÎÖеıäÁ¿£¬ÕâЩ±äÁ¿±»³ÆΪ×ÔÓɱäÁ¿¡£

±Õ°üº¯ÊýµÄÓÅÊÆ

±Õ°üº¯ÊýÓÐÒÔÏÂÓÅÊÆ£º

Êý¾Ý˽Óл¯£º×ÔÓɱäÁ¿¿ÉÒÔ·â×°ÔÚ±Õ°üº¯ÊýÖУ¬Ê¹Æä¶ÔÍⲿ´úÂë²»¿É¼û£¬´Ó¶øʵÏÖÊý¾Ý˽Óл¯¡£

״̬ÖÎÀí£º±Õ°üº¯Êý¿ÉÒÔ´æ´¢ºÍÖÎÀí״̬£¬×ÝÈ»ÔÚÍⲿº¯ÊýÖ´ÐÐÍê±Ïºó£¬×´Ì¬ÈÔÈ»¿ÉÒÔ±£´æ¡£

»Øµ÷º¯Êý£º±Õ°üº¯Êý¿ÉÒÔ×÷Ϊ»Øµ÷º¯Êý£¬ÔÚÒì²½²Ù×÷Íê³ÉºóÖ´ÐÐÌض¨Ê¹Ãü¡£

±Õ°üº¯ÊýµÄʾÀý

ÒÔÏÂÊÇÒ»¸ö±Õ°üº¯ÊýµÄʾÀý£º

function outerFunction(x) {
  let y = 10;

  function innerFunction() {
    return x + y;
  }

  return innerFunction;
}

const inner = outerFunction(5);
console.log(inner()); // Êä³ö£º15

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖУ¬innerFunction ÊÇÒ»¸ö±Õ°üº¯Êý£¬ËüÓµÓÐ×ÔÓɱäÁ¿ x ºÍ y¡£×ÝÈ» outerFunction ÒѾ­Ö´ÐÐÍê±Ï£¬innerFunction ÈÔÈ»¿ÉÒÔ»á¼û x ºÍ y¡£

ÒÔÉϾÍÊÇjsÖÐʲôÊDZհüº¯ÊýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ