This article describes the usage of arguments.callee in Javascript functions. Share it with everyone for reference, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script type="text/javascript"> //Method 1. This method cannot implement recursive factorials when the function name fac points to a new function // function fac(num) {// if (num <= 1) {// return 1;// }// else {// return num * fac(num - 1);// } // Method 2 function fac(num) { if (num <= 1) { return 1; } else { return num * arguments.callee(num - 1); //arguments.callee represents a reference to the current method} } window.onload = function () { var func = fac; fac = function () { //Point to the new function return 1; } alert(func(5)); //Use method one to output 5, use method two to output the factorial value of 5 alert(fac(5)); //Output 1 } </script></head><body></body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript array operation techniques", "Summary of JavaScript mathematical operation usage methods", "Summary of JavaScript data structures and algorithm techniques", "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques" and "Summary of JavaScript traversal algorithms and techniques"
I hope this article will be helpful to everyone's JavaScript programming.