【问题标题】:Get CurrentMethodName in javascript [duplicate]在javascript中获取CurrentMethodName [重复]
【发布时间】:2012-05-14 14:29:56
【问题描述】:

可能重复:
Can I get the name of the currently running function in javascript?

在 Javascript 中有没有一种方法可以获取执行 javascript 的方法/函数的名称。 我想要

alert('此消息在方法内运行时出现' + GetCurrentMethodName());

【问题讨论】:

    标签: javascript


    【解决方案1】:

    像这样使用arguments.callee.name

    alert('This message is coming while running inside the method ' + arguments.callee.name);
    

    【讨论】:

    • 不适用于分配给方法的匿名函数
    • 那是因为匿名函数没有名字...
    • 那么,这只会返回一个空字符串。
    • @FlorianMargaine:没错。 :)
    • 当然,但我认为 OP 想要 方法标签(例如 someobj.NAME 将是 NAME)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2014-03-11
    • 2015-05-11
    • 2023-03-24
    • 2021-09-14
    • 2011-04-15
    • 1970-01-01
    相关资源
    最近更新 更多