The function deeply understands the internal properties of the---function arguments and this

Source: Internet
Author: User

argumentsfunctionsay (num) {/*there is a property called arguments in the function object, which can be used to obtain the corresponding parameter value, which is an array, which is actually the parameter passed in.*/Console.log (arguments.length);  for(vari=0;i<arguments.length;i++) {Console.log (arguments[i]); } console.log (num);}/*in arguments This object has a callee method, Arguments.callee (ARG) can reverse the call*///say (a);//This is coupled with the function name//return num * factorial (num-1);//The following is the implementation of the function name of the decoupling, in JS is usually used in this way to do recursionfunctionfactorial (num) {if(num<=1){        return1; }Else{        returnNum*arguments.callee (num-1); }}/*The above is a function of factorial, the function name of the recursive call and the original function name are coupled together if the function name changes in the future after the recursive call will be invalidated*/varCF =factorial;//no error at this timeConsole.log (CF (5)); factorial=NULL;//at this point, because the CF function is still called with the name factorial, but Factorial has pointed to null, so it will be an error//recursive calls are invalidatedConsole.log (CF (5));  This

/*when a class needs to be created, the properties and methods of the set class need to be referenced by the This keyword, but it is particularly important to note that the This keyword will be different when called by different harmonic objects*/varcolor = ' Red ';functionShowcolor () {Console.log ( This. color);}//created a class that has a color property and a Show methodfunctionCircle (color) { This. color =color; This. Showcolor =Showcolor;}varc =NewCircle (' Yellow ');//using C to call the Showcolor method is equivalent to calling the Showcolor () method//This is C, so color is yellowC.showcolor ();//Yellow//the object called at this time, and so window,showcolor this is the window, so you will find the window colorShowcolor ();//Red

The function deeply understands the internal properties of the---function arguments and this

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.