我们能否在运行时附加的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