Javascript: The Length attribute of the function.

Source: Internet
Author: User

The typeof operator returns the string "function" when used in a function, but the function is indeed a special type of JavaScript Object. Since functions are also objects, they should have attributes.

Attribute length

As we know, in the function body, The Length attribute of the arguments array specifies the number of arguments passed to the function. HoweverThe Length attribute of the function itself.It is a read-only feature,Returns the number of real parameters required by the function,That is, the number of parameters declared in the parameter list of the function. When calling a function, you can pass any number of real parameters to it. The function can obtain these parameters from the arguments array without considering the number of declared parameters. The Length attribute of the function object specifies the number of parameters declared by a function. Note: Unlike arguments. length, this Length attribute is valid both inside and outside the function body.

The following code defines a function named check ().Arguments. LengthAndArguments. callee. LengthTo determine whether the number of parameters passed to the function meets the requirements. Function check () is a detection function f (). The Code is as follows:

<HTML> 

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.