我們能否在運行時附加的ArrayList或功能與JavaScript對象JavaScript的數組列表
function abc(){
this.a = 1;
this.b = 2;
}
var obj = new abc();
obj.list.add("abc"); // list is not declare in class abc
我們能否在運行時附加的ArrayList或功能與JavaScript對象JavaScript的數組列表
function abc(){
this.a = 1;
this.b = 2;
}
var obj = new abc();
obj.list.add("abc"); // list is not declare in class abc
function abc(){
this.a = 1;
this.b = 2;
}
var obj = new abc();
obj.list = ["abc"];
var obj = new abc();
obj.list = [];
obj.list.unshift("abc");
function abc(){
this.a = 1;
this.b = 2;
}
var obj = new abc();
obj.list = new Array();
obj.list.push("abc");
我認爲你需要寫
obj.push("abc")
,你首先必須要聲明列表,那麼你可以訪問/修改它作爲任何其他對象prop:
var obj = new abc();
obj.list = [];//or obj.list = new Array();
obj.list.add("abc");
你在問什麼? –
@Arslan Ahson我認爲你應該讀一點,然後來這裏問問題,甚至在維基百科解釋! – Bakudan