• <legend id='ZiAlI'><style id='ZiAlI'><dir id='ZiAlI'><q id='ZiAlI'></q></dir></style></legend>

      <tfoot id='ZiAlI'></tfoot>

          <bdo id='ZiAlI'></bdo><ul id='ZiAlI'></ul>

        <small id='ZiAlI'></small><noframes id='ZiAlI'>

        <i id='ZiAlI'><tr id='ZiAlI'><dt id='ZiAlI'><q id='ZiAlI'><span id='ZiAlI'><b id='ZiAlI'><form id='ZiAlI'><ins id='ZiAlI'></ins><ul id='ZiAlI'></ul><sub id='ZiAlI'></sub></form><legend id='ZiAlI'></legend><bdo id='ZiAlI'><pre id='ZiAlI'><center id='ZiAlI'></center></pre></bdo></b><th id='ZiAlI'></th></span></q></dt></tr></i><div id='ZiAlI'><tfoot id='ZiAlI'></tfoot><dl id='ZiAlI'><fieldset id='ZiAlI'></fieldset></dl></div>

        ΪʲôҪʹÓÃjavascriptº¯Êý°ü×°Æ÷(ÔÚcoffeescriptÖÐÌí¼Ó)¡°.call(this)"?

        ʱ¼ä£º2024-04-20
        • <tfoot id='IeRVU'></tfoot>
            <bdo id='IeRVU'></bdo><ul id='IeRVU'></ul>
              <tbody id='IeRVU'></tbody>

            <legend id='IeRVU'><style id='IeRVU'><dir id='IeRVU'><q id='IeRVU'></q></dir></style></legend>
              <i id='IeRVU'><tr id='IeRVU'><dt id='IeRVU'><q id='IeRVU'><span id='IeRVU'><b id='IeRVU'><form id='IeRVU'><ins id='IeRVU'></ins><ul id='IeRVU'></ul><sub id='IeRVU'></sub></form><legend id='IeRVU'></legend><bdo id='IeRVU'><pre id='IeRVU'><center id='IeRVU'></center></pre></bdo></b><th id='IeRVU'></th></span></q></dt></tr></i><div id='IeRVU'><tfoot id='IeRVU'></tfoot><dl id='IeRVU'><fieldset id='IeRVU'></fieldset></dl></div>

            1. <small id='IeRVU'></small><noframes id='IeRVU'>

                  ±¾ÎĽéÉÜÁËΪʲôҪʹÓÃjavascriptº¯Êý°ü×°Æ÷(ÔÚcoffeescriptÖÐÌí¼Ó)¡°.call(this)"?µÄ´¦Àí·½·¨£¬¶Ô´ó¼Ò½â¾öÎÊÌâ¾ßÓÐÒ»¶¨µÄ²Î¿¼¼ÛÖµ£¬ÐèÒªµÄÅóÓÑÃÇÏÂÃæËæןú°æÍøµÄС±àÀ´Ò»Æðѧϰ°É£¡

                  ÎÊÌâÃèÊö

                  µ±ÎÒʹÓÃ×îР(1.0) °æ±¾µÄ¿§·È½Å±¾Ê±£¬Ò»¸ö¼òµ¥µÄ javascript Êä³ö¿´ÆðÀ´ÏñÕâÑù(ĬÈÏÇé¿öÏÂ):

                  When I use the latest (1.0) release of coffee-script, a simple javascript output looks like this (by default):

                  (function() {
                    var a;
                    a = 1;
                  }).call(this);
                  

                  .call(this) ÓÐʲô×÷ÓÃÒÔ¼°Ìí¼ÓËüµÄÔ­ÒòÊÇʲô?

                  What does .call(this) do and what would be the reason to add it?

                  ÍƼö´ð°¸

                  ËüÕýÔÚ´´½¨Ò»¸öº¯Êý£¬È»ºóʹÓø¸º¯Êý/¶ÔÏó·¶Î§µ÷ÓÃ×ÔÉí.

                  It's creating a function and then calling itself with the parent function/objects scope.

                  .call ºÍ .apply Êǵ÷Óú¯ÊýµÄ²»Í¬·½·¨.Äú»ù±¾ÉÏ´´½¨ÁËÒ»¸öº¯Êý£¬³ýÁËÔÚ×Ô¼ºµÄ·¶Î§ÄÚÉèÖà a=1 Ö®Íâʲô¶¼²»×ö.

                  .call and .apply are different methods of invoking a function. You basically created a function that does nothing except set a=1 within its own scope.

                  ÔÚ javascript ÖÐÄãÐèÒªÒâʶµ½Ã¿¸öº¯Êý¶¼ÊÇÒ»¸ö¶ÔÏ󣬶ø this ÊÇÖ¸µ±Ç°µÄ¶ÔÏó/º¯Êý.ʹÓà .call(this) ¸²¸Çº¯ÊýÄÚµÄ this ²¢½«ÆäÌ滻Ϊµ÷ÓÃÉÏÏÂÎÄÖеÄÄǸö.

                  In javascript you need to realize that every function is a object, and this is what refers to the current object/function. Using .call(this) overrides this from within the function and replaces it with the one from the calling context.

                  Õâƪ¹ØÓÚΪʲôҪʹÓÃjavascriptº¯Êý°ü×°Æ÷(ÔÚcoffeescriptÖÐÌí¼Ó)¡°.call(this)"?µÄÎÄÕ¾ͽéÉܵ½ÕâÁË£¬Ï£ÍûÎÒÃÇÍƼöµÄ´ð°¸¶Ô´ó¼ÒÓÐËù°ïÖú£¬Ò²Ï£Íû´ó¼Ò¶à¶àÖ§³Ö¸ú°æÍø£¡

                  ÉÏһƪ£ºÕâÖÖ×Ôµ÷ÓÃÄäÃûº¯Êý±äÌå±³ºóµÄÔ­Òò ÏÂһƪ£º´Ó Promise ½á¹ûÖе¼³ö Node Ä£¿é

                  Ïà¹ØÎÄÕÂ

                  <small id='E9HNd'></small><noframes id='E9HNd'>

                  <i id='E9HNd'><tr id='E9HNd'><dt id='E9HNd'><q id='E9HNd'><span id='E9HNd'><b id='E9HNd'><form id='E9HNd'><ins id='E9HNd'></ins><ul id='E9HNd'></ul><sub id='E9HNd'></sub></form><legend id='E9HNd'></legend><bdo id='E9HNd'><pre id='E9HNd'><center id='E9HNd'></center></pre></bdo></b><th id='E9HNd'></th></span></q></dt></tr></i><div id='E9HNd'><tfoot id='E9HNd'></tfoot><dl id='E9HNd'><fieldset id='E9HNd'></fieldset></dl></div>

                1. <legend id='E9HNd'><style id='E9HNd'><dir id='E9HNd'><q id='E9HNd'></q></dir></style></legend>
                  <tfoot id='E9HNd'></tfoot>

                      <bdo id='E9HNd'></bdo><ul id='E9HNd'></ul>