Getting All Variables In Scope

前端 未结 10 2151
小蘑菇
小蘑菇 2020-11-22 09:10

Is there a way to get all variables that are currently in scope in javascript?

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 09:53

    The Simplest Way to Get Access to Vars in a Particular Scope

    1. Open Developer Tools > Resources (in Chrome)
    2. Open file with a function that has access to that scope (tip cmd/ctrl+p to find file)
    3. Set breakpoint inside that function and run your code
    4. When it stops at your breakpoint, you can access the scope var through console (or scope var window)

    Note: You want to do this against un-minified js.

    The Simplest Way to Show All Non-Private Vars

    1. Open Console (in Chrome)
    2. Type: this.window
    3. Hit Enter

    Now you will see an object tree you can expand with all declared objects.

提交回复
热议问题