Javascript equivalent of Python's locals()?

后端 未结 6 1573
离开以前
离开以前 2020-11-29 11:54

In Python one can get a dictionary of all local and global variables in the current scope with the built-in functions locals() and globals(). Is t

6条回答
  •  难免孤独
    2020-11-29 12:45

    Well, I don't think that there is something like that in js. You can always use eval instead of locals(). Like this:

    eval(s+"()");
    

    You just have to know that actually function foo exists.

    Edit:

    Don't use eval:) Use:

    var functionName="myFunctionName";
    window[functionName]();
    

提交回复
热议问题