Javascript callee and caller

Source: Internet
Author: User

The main purpose of arguments is to save parameters, but it also has the callee attribute. 1. callee points to the function of the arguments object. example 1: 1 function calture (num) {// factorial calculation 2 if (num <= 1) return 1; 3 else {4 return num * calture (num-1 ); 5} 6} A calture call is made in the Code. this is very unfavorable in future code maintenance. if the name of the function outside is changed one day, it will not be changed. You will understand the consequences. this problem can be optimized like this: 1 function calture (num) {// factorial calculates 2 if (num <= 1) return 1; 3 else {4 return num * arguments. callee (num-1); 5} 6} 2: caller stores the reference of the function that calls the current function. If it is called in a global scope, its value is null. copy code 1 function Me () {2 You (); 3} 4 function You () {5 alert (You. caller); 6} 7 Me (); copy code effect: optimize the code above: Copy code 1 function Me () {2 You (); 3} 4 function You () {5 alert (arguments. callee. caller); 6} 7 Me (); copy the code

Related Article

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.