cocos2d js 自定义类里面添加数组的问题

testArray = ];

var HelloWorldLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
//////////////////////////////
// 1. super init first
this._super();
for(var i = 0;i<5;i++)
{
var sp = new HeadSprite(“res/CyanSquare.png”);
sp.x = 100 + i100;
sp.y = 200;
this.addChild(sp);
testArray
=sp;
}

                                  testArray.haveBetedArray.push(5);
                                  testArray.haveBetedArray.push(6);
                                  testArray.haveBetedArray.push(7);
                                  testArray.num = 12;
                                  

                                  
                                  var l1 = testArray.haveBetedArray.length;
                                  var l2 = testArray.haveBetedArray.length;
                                  var l3 = testArray.haveBetedArray.length;
                                  
                                  for(var j=0;j<testArray.haveBetedArray.length;j++)
                                  {
                                  cc.log("l2 == " + testArray.haveBetedArray );
                                  }
                                  
                                  
                                  cc.log("l1 == " + l1 +  " l2 == " + l2 + " l3 == " + l3);
                                  cc.log(" l1 num ==  "  + testArray.num  + " - -  l2  num ==  " +  testArray.num);
                                  
                                  
                                  

                                  
    return true;
}

});

var HeadSprite = cc.Sprite.extend({

                            haveBetedArray:],
                              num:0,
                              ctor:function (arg) {
                              this._super(arg);
                              
                              },
                              
                              });

打印:
cocos2d: JS: l2 == 5
cocos2d: JS: l2 == 6
cocos2d: JS: l2 == 7
cocos2d: JS: l1 == 3 l2 == 3 l3 == 3
cocos2d: JS: l1 num == 12 - - l2 num == 0

我想在 HeadSprite 里添加一个 数组属性 haveBetedArray 然后动态添加元素 不过效果上好像 数组是静态的, 刚接触 cocos2dx js 有人知道 在js 里添加动态数组 怎么实现吗 类似oc 里的 nsarray 和 cocos2dx 里的 ccarray 的结构

    元素里属性的数组 效果是静态的  就是 自定义类共享的 ?

我又试了一下

                                     var sp = new HeadSprite("res/CyanSquare.png");
                                     sp.x = 100 + 100;
                                     sp.y = 200;
                                     this.addChild(sp);
                                  sp.haveBetedArray.push(5);
                                  sp.haveBetedArray.push(6);
                                  
                                  
                                  var sp1 = new HeadSprite("res/CyanSquare.png");
                                  sp1.x = 100 + 300;
                                  sp1.y = 200;
                                  this.addChild(sp1);
                                  
                                  cc.log("  sp  length == " + sp.haveBetedArray.length + " sp1 length ==  " + sp1.haveBetedArray.length );

打印 cocos2d: JS: sp length == 2 sp1 length == 2

自定义类里的数组就是 静态的啊! 有什么可以代替的吗? 实现 ccarray 的功能就可以
公司逼着转cocos2dx js 累啊!!!!

好吧 自己解决了
自定义类的时候 加个步骤 就可以了 功能就可以实现了,

var HeadSprite = cc.Sprite.extend({

                              haveBetedArray:null,
                              num:0,
                              ctor:function (arg) {
                              this._super(arg);

                        
 this.haveBetedArray = new Array();


                              },
                              
                              });

HeadSprite.prototype.setArayValue = function(value){

this.haveBetedArray.push(value);

}

我也遇到同样的问题了,谢了哥们