Use watchpoints - Firefox Developer Tools 编辑

When debugging JavaScript code, it can be useful to know when properties on objects are read or modified. In a large, complex codebase, it's not always easy to know where in the code a given property is accessed. In the Firefox Debugger, this information can be provided by watchpoints. By setting a watchpoint on the property, rather than a breakpoint at a particular line, you can discover where that access occurs. 

There are three types of watchpoints: get, set, and get or set. A get watchpoint pauses whenever a property is read; a set watchpoint pauses whenever a property value changes; a get or set watchpoint pauses whenever a property value is accessed in either way.

Set a watchpoint

  1. Run and then pause the debugger.
  2. In the Scopes pane on the right side of the Debugger user interface, find an object you want to watch, and right-click it to open its context menu.
  3. Choose Break on, and then one of
    • Property set
    • Property get
    • Property get or set
    Screenshot showing the context menu for setting a watchpoint on an object
    A watchpoint icon appears to the right of the property in the Scopes pane. Set watchpoint icons are blue, get watchpoint icons are reddish, and get or set watchpoint icons are dark yellow.
    Screenshot highlighting the 3 types of watchpoint icons
  4. Click Play or press F8 to resume execution.

View a watchpoint

When the watched property is accessed in the way specified by the watchpoint type (get or set), the debugger pauses, enabling you to see line of code responsible, and to inspect anything else you wish at that time.

In the following screenshot, the debugger pauses at line 7, where obj.a is set. The message panel in the upper right corner indicates that the debugger is "Paused on property set".

Delete a watchpoint

  1. Locate the watched property in the Scopes pane.
  2. Click the watchpoint icon, or right-click and choose Remove watchpoint. The watchpoint is removed.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:98 次

字数:3422

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文