为什么在JavaScript父变量中取值子变量的值?

时间:2013-03-06 05:14:18

标签: javascript jquery

请帮我解决下一个问题。

var a = _b; //_b and _c is arguments. _b is array of objects (length = 1), _c is integer value
if (a.length != 0)
{
   $.each(a,function(k,v){
     if (v.c!= _c)
       a.splice(k,1);//here a becomes empty, but _b becomes empty too. i don't know why.
   }); 
   if (a.length != 0){
      _b = a;
   }
}

我做错了什么?

1 个答案:

答案 0 :(得分:3)

变量a是对数组_b的引用,而不是副本,因此清空a也会清空_b