有没有一种方法可以“观看"谷歌浏览器中的变量? [英] Is there a way to "watch" a variable in google chrome?

查看:266
本文介绍了有没有一种方法可以“观看"谷歌浏览器中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想在每次更改给定的闭合变量时添加一个断点.有什么办法吗?

Basically, I want to add a breakpoint every time a given closure variable is changed. Is there any way to do this?

推荐答案

我认为目前尚无一种直接 监视变量的方法,但是如果您可以将闭包变量放在对象中,那么您可以使用Object.observe()观察该对象的更改. (Object.observe只能观察对象)
这要求您启用实验性Javascript-chrome://flags/#enable-javascript-harmony.

I don't think there's currently a way to directly watch variables, but if you can put the closure variable in an object, then you can use Object.observe() to observe that object for changes. (Object.observe can only observe objects)
This requires you to have Experimental Javascript enabled - chrome://flags/#enable-javascript-harmony.

(function(){
  var holder = { 
    watchedVariable: "something"
  };

  Object.observe(holder, function (changes) {
    // returns an array of objects(changes)

    if ( changes[0].name === "watchedVariable" ) {
      debugger;
    }

  });

})()

这篇关于有没有一种方法可以“观看"谷歌浏览器中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆