Javascript equivalent of Python's locals()?

后端 未结 6 1563
离开以前
离开以前 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:50

    I seem to remember Brendan Eich commented on this in a recent podcast; if i recall correctly, it's not being considered, as it adds unreasonable restrictions to optimization. He compared it to the arguments local in that, while useful for varargs, its very existence removes the ability to guess at what a function will touch just by looking at its definition.

    BTW: i believe JS did have support for accessing locals through the arguments local at one time - a quick search shows this has been deprecated though.

提交回复
热议问题