Ext JS Learning the fourth day we are familiar with JavaScript (iii)

Source: Internet
Author: User

This article is used to record learning notes;

JavaScript function This the use of the keyword –this keyword always points to the caller, who calls the function, this points to who call, apply the use of –call and apply the main application and the framework of the underlying, for the binding function of the execution environment/scope • Block concept – Unlike high-level programming languages, there is no block concept in JS, we generally wrap block-level scopes and closures with parentheses: Mastering closures must be well-understood concepts – execution Environment – scope chain – garbage collection mechanism with chestnut code attached
1 //The This keyword is used in JavaScript2 //The This keyword always points to the caller, who calls the function, and this points to who3 varx =5;//window.x = 5;4 function Test () {5Alert This. x); 6 };7Test.x =Ten;//give the function a static variable x8alert (test.x);//Ten9Window.test ();//5Ten  One  A //the main role of call apply is the binding scope - varcolor ='Red'; - varobj = {color:'Yellow'}; the  - function Showcolor (x, Y, z) { -Alert (x+y+z); -Alert This. color); + }; - ////Call, apply binds a function to execute within the scope you specify +Showcolor.call (window,Ten, -, -);//Red AShowcolor.call (obj,Ten, -, -);//Yellow atShowcolor.apply (obj, [2,3,4]);//Yellow 9 -  - //concept of block: - function Test () { - (function () { -          for(vari =1; I <=5; i++){ in alert (i); -         }     to     })(); +alert (i);//undefined - }; the test (); *  $ //closures: Execution environment, scope chain, JS garbage collectionPanax Notoginseng //The function returns directly to the return, without renturn returning the result undefined - //in the JavaScript language: The use of global variables (1: Unsafe, 2: Variable search finding is less efficient) the function Test () { +     returnfunction () { AAlert'I am the closure of the package body code ...'); the     }; + }; - varf =test (); $Alerttypeoff);//function $f ();//I am the closure of the package body code ... -  - function Test () { the     vartemp =Ten ; -     returnfunction () {Wuyi alert (temp); the     }; - }; Wu test () (); -  About  $ //Avoid using global variables click buttons to count clicks - varINP =(function () { -     vari =0; -     return { A getcount:function () { +Alert (+ +i); the         } -     }; $})();

Recommended to you a beautiful article network www.fishcmonkey.com, learning to improve literary accomplishment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.