我在这里有一个很好的问题。我需要了解这个原型对象的数组
Foo = function(){
};
Foo.prototype = {
buttons: new Array(),
index:'',
add: function(value)
{
this.buttons.push(value);
},
clear:function(){
this.buttons=new Array();
},
count:function(){
return(this.buttons.length);
},
setIndex:function(index){
this.index;
},
getIndex:function(index){
return this.index;
}
};
var A= new Foo();
var B= new Foo();
A.add('toto');
B.add('tata');
A.setIndex(8);
B.setIndex(44);
alert(A.count()+"---"+A.getIndex());
该代码给我:“2 --- 8”!
所以A.count()返回给我A.count()+ B.count()。与B.count()一样!
任何人都可以解释我这个,已经有这个问题吗?怎么做 ?我只需要数组“按钮”是唯一的,适合每个对象。
知识缺失!非常感谢你 – Flozza 2013-03-08 19:51:07