zoukankan      html  css  js  c++  java
  • arguments.callee

    var i = 2
    function f() {
      console.log(i)
      i = i - 1;
      if (i > 0) arguments.callee()
    }
    function f2(){
      f()
    }
    f2()

    如何在JavaScript函数中获取函数名称?

    怎么可能学习我所在的功能名称? 以下代码警告'对象'。但我需要知道如何警告“外面”。
    function Outer(){
    
        alert(typeof this);
    
    }
    
        
    我认为你可以这样做:
    var name = arguments.callee.toString();
    
    有关这方面的更多信息,请查看本文。
    function callTaker(a,b,c,d,e){
      // arguments properties
      console.log(arguments);
      console.log(arguments.length);
      console.log(arguments.callee);
      console.log(arguments[1]);
      // Function properties
     console.log(callTaker.length);
      console.log(callTaker.caller);
      console.log(arguments.callee.caller);
      console.log(arguments.callee.caller.caller);
      console.log(callTaker.name);
      console.log(callTaker.constructor);
    }
    
    function callMaker(){
      callTaker("foo","bar",this,document);
    }
    
    function init(){
      callMaker();
    }
    
        

    辅奈

     

    这将有效:
    function test() {
      var z = arguments.callee.name;
      console.log(z);
    }
    
        

    目前的答案已经过时了。从ES6开始,你可以使用

    Function.prototype.name

    。这具有使用箭头函数的额外好处,因为它们没有自己的参数对象。

    function logFuncName() {
      console.log(logFuncName.name);
    }
    
    const logFuncName2 = () => {
      console.log(logFuncName2.name);
    };
    
  • 相关阅读:
    蓝桥杯如何训练?(附VIP题库)
    scratch2.0的教材视频,王木头系列
    out文件 dev c++
    MongoDB 学习笔记
    golang 学习笔记 -- struct interface的使用
    goang学习笔记---struct
    golang 学习笔记 ---JSON
    golang学习笔记 ---rand
    golang学习笔记 --go test
    golang学习笔记---string && strconv
  • 原文地址:https://www.cnblogs.com/xsSystem/p/12034834.html
Copyright © 2011-2022 走看看