Arguments object, apply (), anonymous function

Source: Internet
Author: User

When learning arguments objects, a piece of code encountered is not too good to understand. Original address Chinese (http://www.jb51.net/article/25048.htm), English (http://www.sitepoint.com/arguments-a-javascript-oddity/)

To understand correctly, you need to grasp the place of the red mark.

1,function.prototype.apply () Usage

2. Need to understand MajorTom here points to anonymous function functions () {return func.apply (null, Args.concat ( Array.prototype.slice.call (arguments)));}

<! DOCTYPE html>functionFormat (string) {varargs =arguments; varPattern =NewREGEXP ("% ([1-" + Arguments.length + "])", "G"); returnString (String). replace (pattern,function(match, index) {returnArgs[index];        }); }        functionMakefunc () {varargs =Array.prototype.slice.call (arguments); varFunc =Args.shift (); return function () {                return func.apply (Null , Args.concat (Array.prototype.slice.call (arguments)));        }; }        varMajorTom= Makefunc (Format, "This was Major Tom to ground control. I ' m%1. "); Console.log (MajorTom ("Stepping through the door");//MajorTom is a reference to an anonymous function "</script>

Arguments object, apply (), anonymous function

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.