我如何获得JavaScript函数中的函数名称? [英] How can I get the name of function inside a JavaScript function?

查看:93
本文介绍了我如何获得JavaScript函数中的函数名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何学习函数名称?

下面的代码提示'Object'。但我需要知道如何提醒外。

The below code alerts 'Object'. But I need to know how to alert "Outer."

function Outer(){

    alert(typeof this);

}


推荐答案

你可以这样做:

var name = arguments.callee.toString();

有关这方面的更多信息,请查看本文

For more information on this, take a look at this article.

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();
}

这篇关于我如何获得JavaScript函数中的函数名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆