I want to refactor this code into js object, but not sure how. How should I do it?
I initialize an object for every item in the DS.data_per_folder array. how can I define it in a higher level? Where should I init it then?
..
DS.data_per_folder[CurrentContextMgr.current.folder.attr('id')] = {
allAttachments_vector: [],
allAttachments_vector_counter : 0,
attachment_position_dict : {},
extraDetails_dict: {},
getAttachmentsPerPage: function (pageNum) {
var result = this.allAttachments_vector.slice(global_vars.NUM_OF_ATTACH_PER_PAGE * (pageNum - 1), global_vars.NUM_OF_ATTACH_PER_PAGE * (pageNum));
return result.length == 0 ? null : result;
},
getAttachmentsMarkupPerPage: function (pageNum) {
var attachmentsMarkup = "";
var attachments = this.getAttachmentsPerPage(pageNum);
for (key in attachments) {
attachmentsMarkup += attachments[key].attachment_markup + " ";
}
return (attachmentsMarkup == "") ? "No attachments to display" : attachmentsMarkup;
},
pushAttachment: function (attachment, position) {
//not in dict yet
if (this.attachment_position_dict[attachment.attachmentId] == undefined)
{
if (position == null)
{
position = this.allAttachments_vector_counter;
}
this.allAttachments_vector[position] = attachment;
this.allAttachments_vector_counter++;
this.attachment_position_dict[attachment.attachmentId] = position;
//this.extraDetails_dict[attachment.attachmentId] = {};
}
}, };
}
..