zoukankan      html  css  js  c++  java
  • JavascriptFunction/arguments

    描述:

    创建新的函数.

    语法:

      1. function funName([argu1[,argu2[,...[,arguN]]]]){}
      2. var funName = Function([argu1[,argu2[,...[,arguN]]]]){}

    funName是必不可少的.

    例子:

    例子 效果
            function add(x,y){
                return x+y;
            }
            
            document.write(add(1,2));
    3
            var add = new Function("x","y","return x+y");
            
            document.write(add(1,2));
    3

    属性:

    属性 描述
    arguments 对当前执行的function对象返回一个arguments对象
    caller 返回一个对函数的引用,该函数调用了当前函数

    arguments:

    不能显示的创建arguments对象,arguments对象只有在函数开始时才可用.

    函数的arguments对象并不是一个数组,但可以想数组一样使用下标去访问.

    属性 描述
    [i] i:必须.
    返回第i个参数的值
    语法:
    arguments[i]
    length 返回该函数的参数的个数
    语法:
    arguments.length
    callee 返回正在被执行的Function对象,即返回自身

    例子:

    例子 效果
            function Calls(x,y){
                
                document.write("args:"+arguments.length+"<br/>");
                for(var i=0;i<arguments.length;i++){
                    document.write("args["+i+"]="+arguments[i]+"<br/>");
                }
            }
            
            Calls(1,2);
    image
            function add(x){
                if(x==1){
                    return 1;
                }else{
                    return x+arguments.callee(x-1);
                }
            }
            
            document.write(add(100));
    image
  • 相关阅读:
    MySQL数据模型
    Spring循环依赖
    @Autowired和@Resource区别
    Kafka概念
    阻塞队列
    线程池原理
    Spring AOP
    JVM 史上最最最完整深入解析(12000 字噢)
    Dubbo配置信息
    友情链接
  • 原文地址:https://www.cnblogs.com/oneword/p/1498396.html
Copyright © 2011-2022 走看看