<title>js– function</title> js– function Table of Contents
- The function array is passed by reference by default
- A function variable is a value pass
- Automatic execution
- Arguments
- Implementing overloading
- anonymous functions
The function array is passed by reference by default
var arr = [1, 2, 3]; function f (a ) {a[0] = null ;} f (ARR); // null 2 3 for (var i = 0; i < 3; i++) {document.write (arr[i]);}
var arr = [1, 2, 3]; function F (a) { null;} f (arr); 1 2 3 for (vari = 0; i < 3; i++) { document.write (arr[i]);}
A function variable is a value pass
var a = 3; function F (b) { b = 4;} F (a);d ocument.write (a); 3
Automatic execution
(Funtion () { varmsg"xxx"; function () { ... do something ... })
Arguments
this . F = function () {if (arguments . Length = = 1) { this . F1 (arguments [0]); } else if ( arguments . Length = = 2) {arguments [0], arguments [1]); }}this . F1 = function (a ) {...} this . F2 = function (a , b ) {...}
Arguments.length;arguments[0], arguments[1], Arguments[2]arguments.callee # callee doesn't look like the outer, it's a closed bag
Alert (function (n) { if (n <= 1) { return 1; Else { returnarguments. callee (n-1); }}) (100));
Implementing overloading
function Power (baseexponent) { varresult = 1; if undefined) { exponent = 2; } for (vari = 1; I <= exponent; i++) { result *= base; } return result;}
anonymous functions
(function(a) {alert (a);}) (' abc ')
JS--function