JavaScript中用户定义对象属性的断点 [英] Break points on User Defined object properties in JavaScript

查看:88
本文介绍了JavaScript中用户定义对象属性的断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



您好



是否有任何JavaScript调试工具或插件有助于在
用户定义的对象属性上设置断点。



例如:



我有一个JavaScript对象文字




var TextBox = {
color:gray,
size :100px,
border:true
}



这是我的代码修改




function foo(){
TextBox [color] =blue
}



我正在寻找在 TextBox.color 上放置一个断点当财产被修改时,我可以找到
谁正在进行修改或哪个功能进行更改。



它也应该破坏

TextBox.color = null;

删除TextBox.color;



此功能是否已在firebug或chrome开发人员工具中使用?



我已经看到html元素删除的断点,属性修改
,但不是用于用户定义的对象属性



谢谢

解决方案

看看某些浏览器支持的魔术吸引器和设置器:
https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects #Defining_getters_and_setters



您应该能够定义一个设置器并在其中放置一个断点。



出于兼容性原因,可能最好保持这些生产代码,但它们是调试某些问题的唯一实用方法。


Break points on User Defined object properties in javascript

Hello

Is there is any JavaScript debugging tool or addon that helps to put break points on User Defined object properties.

Eg:

I have a JavaScript Object Literal

var TextBox = { color:"gray", size:"100px", border:true }

Here is my code that does the modification

function foo(){ TextBox["color"] = "blue"; }

I am looking for putting a breakpoint on TextBox.color so that when the property is modified I could find who is doing the modification or which function does the alteration.

It should also break when TextBox.color = null; or delete TextBox.color;

Is this feature already available in firebug or chrome developer tool?

I have already seen breakpoints for html element removal , attribute modification but not for user defined object properties.

Thanks.

解决方案

Have a look at the magic getters and setters that some browsers support: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects#Defining_getters_and_setters

You should be able to define a setter and put a breakpoint in it.

Probably best to keep these out of production code for compatibility reasons, but they're the only practical way to debug certain problems.

这篇关于JavaScript中用户定义对象属性的断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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