// build this how you were
conversations = {};
// if conversations[12345] is defined, use it:
// else set it to an object with the desired properties/methods
conversations["12345"] = conversations["12345"] || { name : "Frank", messages : [] };
conversations["12345"].messages.push(new_msg);
我假设您将在 XHR 或其他函数中执行此操作
conversations.add_message = function (msg) {
var id = msg.conversation_id;
conversations[id] = conversations[id] ||
conversations.new_conversation(msg.user_name); // returning a conversation object
conversations[id].messages.push(msg);
};
conversations.new_conversation = function (name) {
return { name : name, messages : [], etc : {} };
};