我正在创建一个Javascript框架,这是我的问题:我有一个对象和一个数组。每次我调用对象时,我都需要清除数组。如何在每次调用对象时运行函数
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}
}
所有我需要知道的是如何每次我记得obj的对象时清除阵列
//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();
所有我想要的是让这个每次OBJ被调用时清除阵列。
我需要一提的是,我将在这环环相扣,我的意思是这样的
obj.getById(“”)(“)getByNames。”;
,所以我需要每个链的数组,然后清除它的对象下次调用
问候
是的,但我需要另一种解决方案,而我将有很多选择,我需要保持阵列上的元素一段时间就像 obj.getById('')。getByNames('') 对于那种情况下,我将需要在链接上的数组元素 抱歉,不提及在这个问题上:) 并感谢您的回答 – Marwan 2011-05-10 13:14:39
所以我需要它每链要保持在阵列,所以链完成后,我再次调用对象,我发现数组清除 – Marwan 2011-05-10 13:15:47
jquery使用该风格,我认为但我不知道它是如何清除数组? – Marwan 2011-05-10 13:16:31