JS--function

Source: Internet
Author: User

<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

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.