dsh77114 2011-11-02 21:45
浏览 22

如何在功能中找到关键词?

Thanks for your help first!

I have some jscripts like:

var id="001";

var name="Jerry";
...

function f1() {
  ...
  var qid="q1";
  ...
}

...
var qid="aaabbb";
...

function f2(){
  ...
  var myid="q1";
  ...
}

...

I want to use regular expression to get the names of function that contains key word "q1". Is there a simple way to do so?

  • 写回答

3条回答 默认 最新

  • dongpang9573 2011-11-02 21:51
    关注

    Functions can be defined within other functions in JavaScript, so using regular expressions to try to solve this problem is impossible. Sorry :-(

    Also, the problem is underspecified. What function name do you want in a case like this?

    function outerFunction(x, y) {
        var innerFunction = function(z) {
            return {
                firstProperty: function() {
                    return "q1";
                }
            };
        };
    }
    

    See? Three different ways to declare a function. How would you create a solution general enough to know the "correct" (most relevant) function name for cases like this?

    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行