我正在尝试填充一个空数组
MessageListFactory = {
messageListCont: new Array()
}
将另一个数组传递的文字对象作为此方法的参数
MessageListFactory.init = function(roomList){
for(var i = 0; i < roomList.length; i++){
var msgL = MessageList.create();
msgL.init(roomList[i].jID, roomList[i].roomName);
console.log(msgL);//Object {messages: Array[0], jID: "c1@xxxx", name: "room S1", notReadMsgCounter: 0, create: function…}
this.messageListCont.push(msgL);//push msgL to MessageListCont
}
console.log(this.messageListCont);//[Object] {length: 0, __proto__: Array[0]}
}
正如您从console.log()
看到的那样,如果我将messageListCont
留空,它会保持在push()
之后。但如果我:
messageListCont : ["foo"]
)messageListCont.push("foo")
)在这些情况下,push
正常工作并且数组已填充。任何人都可以解释我这个吗?