How can I use modules in the browser, but also refer to variables and functions from within DevTools?

后端 未结 2 854
遇见更好的自我
遇见更好的自我 2021-01-20 02:59

I have my HTML setup like this:


and

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 03:53

    One way to make a variable accessable within DevTools is to create it on the window object:

    // Variable in your module
    var importantNumber = 1;
    
    window.importantNumber = importantNumber;
    

    This method works fine if you just have a couple of variables, but if you need to have access to a lot more variables within DevTools, I would recommend you go to the sources-tab in DevTools, search for your module and adding a breakpoint. When the execution pauses, you have access to all the variables within that module on the DevTools console.

提交回复
热议问题