我正在嘗試使用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