__defineSetter__ in Mozilla

If I override a property in Moz with \_\_defineSetter\_\_, can I get at the original property inside my setter function? Say I wanted to add something to a page so that every time someone tried to set anyelement.style.display, it alerted “hello” and then set the value they specified. I could do function setterfn(newstyle) { alert(‘hello’); this.display = newstyle; } CSSStyleDeclaration.prototype.__defineSetter(‘display’,setterfn); Of course, that won’t work, because “this.display” in setterfn calls the setterfn, because it’s trying to set “display” on a style object! Infinite loop. I’m quite happy to do this another way, if setters aren’t the approach. Just don’t suggest Object.watch(), because it’s totally and utterly unreliable on DOM objects and doesn’t fire half the time. The solution can be (and I am expecting it to be) Moz only, but it has to be a proper released version of Moz and not Deer Park. I’ve been trying to do this for two days and it’s doing my head in. :-) (originally a mail for a couple of people, but it occurred to me that I have a weblog for this sort of thing)

More in the discussion (powered by webmentions)

  • (no mentions, yet.)