如何“破坏财产变化”在铬? [英] How to "break on property change" in chrome?

查看:128
本文介绍了如何“破坏财产变化”在铬?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebug的firefox有一个很好的功能,称为破坏属性更改,我可以标记任何对象的任何属性,它将在更改之前停止JavaScript执行。

Firebug for firefox has a nice feature, called "Break on property change", where I can mark any property of any object, and it will stop javascript execution right before the change.

我试图在google chrome中实现相同的功能,而我在chrome调试器中找不到这个功能。如何在Google Chrome中执行此操作?

I'm trying to achieve the same in google chrome, and I can't find the function in chrome debugger. How do I do this in google chrome?

推荐答案

如果您不介意使用源代码,可以重新定义属性与访问者。

If you don't mind messing around with the source, you could redefine the property with an accessor.

// original object
var obj = {
    someProp: 10
};

// save in another property
obj._someProp = obj.someProp;

// overwrite with accessor
Object.defineProperty(obj, 'someProp', {
    get: function () {
        return obj._someProp;
    },

    set: function (value) {
        debugger; // sets breakpoint
        obj._someProp = value;
    }
});

这篇关于如何“破坏财产变化”在铬?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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