Subj : spidermonkey bug or feature? watch on array.length To : netscape.public.mozilla.jseng From : Jens Thiele Date : Thu Aug 26 2004 08:21 pm What I want to do: call a function each time an element is added to an array example: f=function(p,o,n){ println("this[p]:"+this[p]+" p:"+p+" o:"+o+" n:"+n);return n; }; a=[]; a.watch("length",f); a[0]=10; will print: this[p]:0 p:length o:0 n:1 a=[]; a.watch("length",f); a.push(10); will print: this[p]:0 p:length o:0 n:1 this[p]:1 p:length o:1 n:1 => my function is called twice bug or feature? the nice feature of the "second version" is you are called again after the element is added which allows you to inspect the added element Jens .