Subj : Re: spidermonkey watch on object.__count__ To : Jens Thiele From : Brendan Eich Date : Fri Aug 27 2004 11:58 am Jens Thiele wrote: > now i want to call a function each time a property is added to an object > > i had hoped to do this like this: > > o={}; > o.watch("__count__",function(p,o,n){println("this[p]:"+this[p]+" p:"+p+" > o:"+o+" n:"+n);return n;}); > println(o.__count__); > o.x=10; > println(o.__count__); > > output is: > 0 > 1 > > => __count__ is "incremented" but my function isn't called __count__ is magic -- it counts the properties each time you get its value, as if you were calling a function to do that. > > any ideas how to do this (call a function each time a property is added)? You need more hooks than currently exist in the language itself. > if possible in javascript - if not with additional native code (via the > spidermonkey API without changing spidermonkey code) You could use the jsdbgapi.h, I think. > or should the above work and spidermonkey be fixed? Nah, __count__ should not impose costs on ordinary property addition. /be > > Jens .