开发者

Tracking when / where a variable is set in Javascript using FireBug

I am currently using FireBug to see how hypem delivers it the content to allow its flash player to work (specifically the play button functionality). I have found that the trackList variable is populated with the data but I do not know where it is set.

How can I track when / where this collection is modified? I can add a watch to开发者_JAVA百科 it but don't know how to trap when it is set.

FYI I am doing this as I want some of this functionality and want to understand how they have done this.


Here is how you use defineProperty to do it. In my example I'm logging each time window.$ is assigned, along with a call stack. Of course instead of logging you can trigger a debugger; or do something else.

Object.defineProperty(window, "$",
{
  set: function(val) {
    console.log("$ was set to '",val,"' at ",Error().stack);
    this.$internal=val;
  },
  get: function() { return this.$internal; }
});


Unfortunately, this isn't directly possible.

Instead, you can search through the Javascript and see where the variable is set, then put a normal breakpoint on each line that you find.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜