The internal properties of the JS function---arguments,callee,caller

Source: Internet
Author: User

in the next few articles, I'll talk about the internal properties of the function,arguments,callee,caller

(1)arguments, is a class array object, which contains all the parameters of the passed function, the main purpose is to save the parameters of the function;

Code Listing 1:

function AA (b) {alert (arguments);}

AA (4);

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfCNywbl45AABk9A88r80285.jpg "title=" 2.jpg " alt= "Wkiol1ofcnywbl45aabk9a88r80285.jpg"/>


function AA (a,b,c,d) {alert (arguments.length);}

AA (1,2,3,4);

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2F/4E/wKioL1OfCTmhC1iqAABk9A88r80587.jpg "title=" 2.jpg " alt= "Wkiol1ofctmhc1iqaabk9a88r80587.jpg"/>

function AA (a,b,c,d) {alert (arguments[2]);}

AA (1,2,3,4);

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/2F/4D/wKiom1OfCX3gtg6KAABdq8N2zkI114.jpg "title=" JXJ " alt= "Wkiom1ofcx3gtg6kaabdq8n2zki114.jpg"/>

function Hi () {

for (var i=0; i<arguments.length; i++) {

Alert ("Hi," + arguments[i])

}

}

Hi ("Cat", "Alice");

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/2F/4E/wKioL1OfCWOTdHZpAABjhJuZp9I621.jpg "title=" 4.jpg " alt= "Wkiol1ofcwotdhzpaabjhjuzp9i621.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/2F/4D/wKiom1OfCafC-d4FAACDAS6we6Q715.jpg "title=" 5.jpg " alt= "Wkiom1ofcafc-d4faacdas6we6q715.jpg"/>

(2) Another property , Callee, is a pointer to the function that owns the arguments object.

(3) Another property , Calleer, that points to a reference to the function that called the current function.

Arguments.callee Typical applications:

Code 1 :

var i = 1 setTimeout (function () {

Alert (i) if (i++<3) setTimeout (Arguments.callee, 1000)

}, 1000);

Code 2 : (Implementing code decoupling when recursive)

function test1 (num) {

if (num<=1) {

Return 1

}else

Return Num*arguments.callee (num-1);

}

Test1 (5);//120

Arguments.callee.caller

Arguments.callee.caller Example:

f ();

function f () {

alert (Arguments.callee.caller); Undefined

g ();

}

Functiong () {

alert (Arguments.callee.caller);

}

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/2F/4E/wKioL1OfCZfSz3N_AACdpIeu1iE604.jpg "title=" 6.jpg " alt= "Wkiol1ofczfsz3n_aacdpieu1ie604.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/2F/4D/wKiom1OfCdSQIhNXAACo6jDQcDo384.jpg "title=" 7.jpg " alt= "Wkiom1ofcdsqihnxaaco6jdqcdo384.jpg"/>

This chapter is a brief introduction to this, following a few articles, will introduce the function of the most important attributes (no one),prototype and very good two methods, Apply,call (), the level is limited, please give me a lot of advice.


This article is from the "7439523" blog, please be sure to keep this source http://7449523.blog.51cto.com/7439523/1427110

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.