开发者

javascript arraylist

Can we attach arraylist or func开发者_运维百科tion with a javascript object at runtime

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");


I think you need to write

obj.push("abc")


you will first have to declare the list, then you could access/modify it as any other object prop :

 var obj = new abc();
 obj.list = [];//or obj.list = new Array();
 obj.list.add("abc");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜