我正在尝试使用JavaScript对象,但没有变得很远。任何想法,为什么这不起作用?JavaScript获取和设置属性
function Tracking(){
var choices = new Array();
}
Tracking.prototype.getChoice = function (key){
return this.choices[key];
}
Tracking.prototype.setChoice = function (choice){
this.choices.push[choice];
}
function TrackingChoice(key, choice){
this.key = key;
this.choice = choice;
}
.....
var tracking = new Tracking();
var choices = new Array();
choices.push(new TrackingChoice("purchase", true));
choices.push(new TrackingChoice("listing", false));
choices.push(new TrackingChoice("offers", false));
choices.push(new TrackingChoice("messages", false));
tracking.setChoice(choices);
var a = tracking.getChoice(0);
var a
作为选择阵列中的Tracking
对象仍然空是空的。这让我困惑。
甜感谢队友,但我不知道为什么.push( )没有工作,因为我一直在使用它 – sapatos