how to run a function every time i call an object
<p>I'm creating a Javascript framework and this is my problem: I have an object and an array. I need to clear the array every time I call the object. </p>

<pre><code>var obj = 
{
 ary : [],
 getById :function(id){  this.ary[ary.length]= document.getElementById(id); return obj; },
 getByNames :function(names){ //loop over the names parameter and get element by names and then add these elements to the array; return obj; },
show :function(){// in here i loop over the array and show elements}

}
</code></pre>

<p>All I need to know is how to clear that array every time i recall the obj object</p>

<pre><code>//this works perfectly 
obj.get('id').show();
//but when i recall it again like this in debugger mode i see the array have 2 elements not 1 
obj.get('another id').show();
</code></pre>

<p>All I want is to make it so that every time the obj is called to clear the array.</p>

<p>i need to mention it that i will have a chain in this, i mean like that</p>

<p>obj.getById('').getByNames(''); </p>

<p>so i will need the array per chain then clear it in the next call of the object</p>

<p>regards</p>
