Get all Javascript Variables?

前端 未结 4 1616
感情败类
感情败类 2020-12-05 03:30

Is there a way for javascript to detect all assigned variables? For example, if one js file creates a bunch of vars (globally scoped), can a subsequent file get all the vars

4条回答
  •  失恋的感觉
    2020-12-05 03:48

    There is the this variable. This is an object or an array, and you can simply put:

    for(i in this) { //do something }
    

    Unfortunately, it will return everything under the this object.

提交回复
热议问题