zoukankan      html  css  js  c++  java
  • as3 arguments.callee与... (rest)

    import flash.display.Sprite;
    
    var count:int = 1;
    ArgumentsExample()
    function ArgumentsExample()
    {
    	firstFunction();
    }
    
    function firstFunction()
    {
    	trace(count + ": firstFunction");
    	
    	secondFunction(arguments.callee);
    	
    }
    
    function secondFunction(caller:Function)
    {
    	trace(count + ": secondFunction
    ");
    	count++;
    	if(count<3)
    	caller();
    }
    

     输出:

    1: firstFunction
    1: secondFunction

    2: firstFunction
    2: secondFunction

    以上代码演示如何获得对函数的引用,该函数调用名为 secondFunction() 的函数。

    官方解释:

    用于存储和访问函数参数的参数对象。在一个函数体内,可以使用局部参数变量来访问其参数对象。

    这些参数存储为数组元素:第一个存取为 arguments[0],第二个存取为 arguments[1],依此类推。arguments.length 属性表示传递给函数的参数数目。传递的参数数目可能与函数声明的数目有所不同。

    与以前版本的 ActionScript 不同,ActionScript 3.0 中不包含 arguments.caller 属性。要获得对调用当前函数的函数的引用,必须将一个引用作为参数传递给该函数。可从 arguments.callee 示例中找到该技术的示例。 

    针对:要获得对调用当前函数的函数的引用,必须将一个引用作为参数传递给该函数。这句话。理解不透

    ... (rest) parameter 定义关键字 
    
    用法 
    function functionName(parameter0, parameter1, ...rest){ 
    	// statement(s) 
    }  
    

     

    ... (rest)与arguments用法差不多。不过没有arguments的callee方法。

     

  • 相关阅读:
    【React】react学习笔记06-React多组件父子传值
    Requests库基本使用
    HDU1213 How Many Tables(并查集)
    HDU2553 N皇后问题(dfs)
    HDU1312 Red and Black (BFS&&queue)
    Acwing104货仓选址
    设置代理
    修改请求头 -> 设置连接超时 -> 延迟提交数据
    模拟 GET 和 POST 请求
    抓取二进制文件
  • 原文地址:https://www.cnblogs.com/dt1991/p/7714942.html
Copyright © 2011-2022 走看看