Arguments parameters in JavaScript functions _ Basics

Source: Internet
Author: User
I studied the arguments in the JavaScript function a little bit at noon.
Copy Code code as follows:

<script type= "Text/javascript" >
Window.onload = function () {
(Function (arg1, arg2) {
alert (arguments.length);
alert (arguments.callee.length);
})();
}
</script>

Which observed the lower arguments.length and the Arguments.callee

First of all, arguments of course only has meaning in the function body, ARGUMENTS.LENGTH returns the number of arguments passed in the function, such as I did not pass in what, but directly run an anonymous function, then the first alert must be ' 0 ', Again, Arguments.callee returns the called function itself, and for anonymous functions, you can get a reference to it by Arguments.callee. Here Arguments.callee.length returns the number of parameters that the function is expected to pass in, so that the second alert is ' 2 ' if it is a named function, such as a function named MyTest, Then you can directly mytest.length to get the number of parameters that should be passed in.

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.