zoukankan      html  css  js  c++  java
  • arguments.callee 与 函数.caller

    这两个的解释在网上都比较多,但网上一些排版实在让人难受,所以这里用通俗简单的句子再谈谈。

    • arguments.callee 也就是当前函数。
    • 函数.caller 也就是调用当前函数的函数。

    举例

    function F1()
    {
        alert(arguments.callee); //和下面一句的结果相同
        alert(F1); //显示函数 F1 的代码
    }
    F1();
     
    function F2()
    {
        alert(arguments.callee.caller); //和下面一句的结果相同
        alert(F2.caller); //如果被 F3 调用,则显示函数 F3 的代码
        alert(F3); //显示函数 F3 的代码
    }
    function F3()
    {
        F2();
    }
    F3();

    <!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>
    <meta http-equiv="Content-Language" content="zh-cn" />
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>arguments.callee 与 函数.caller</title>
    </head>

    <body>

    <script language="javascript" type="text/javascript">
    <!--
    //千一网络 http://www.cftea.com/

    function F1()
    {
        alert(arguments.callee); //和下面一句的结果相同
        alert(F1); //显示函数 F1 的代码
    }
    F1();
     
    function F2()
    {
        alert(arguments.callee.caller); //和下面一句的结果相同
        alert(F2.caller); //如果被 F3 调用,则显示函数 F3 的代码
        alert(F3); //显示函数 F3 的代码
    }
    function F3()
    {
        F2();
    }
    F3();
    //-->
    </script>

    </body>

    </html>

  • 相关阅读:
    Javascript事件处理进阶
    Restful API设计指南
    Git&GitHub
    Linux补充
    堡垒机
    Python发送邮件
    js获取当前页面url网址信息
    高并发的秒杀系统
    CMDB开发
    Tornado
  • 原文地址:https://www.cnblogs.com/chenlulouis/p/1585788.html
Copyright © 2011-2022 走看看