[jQuery] OT: looking for advise on javascript OOP
Hello friends,
i would like to have some advise on best javascript coding practice .
For my app i first declare an object, then the properties i will use (for easier maintenance ). But i'm unsure on how best to program my UI.refresh() function:
Basically, i pass it an object which should be compared to the existing UI object and wherever a property match, overwrite the old with the new. Everytime there is a change detected, an element must be added to a queue array. Here is my code so far.
One question i have is how best to initalise a string value: with '' or with '' or 'undefined' or ... ?
var UI = new Object();
UI.section = null;
UI.sortBy = null;
UI.dsAnchor = null;
UI.item = null;
UI.menu = null;
UI.content = null;
UI.APP_URL = null;
UI.CURRENT_URL = null;
$(document).ready(function(){
UI.refresh = function(Obj){
var newSection = Obj.section;
var newSortBy = Obj.sortBy;
var newDsAnchor = Obj.dsAnchor;
var newItem = Obj.item;
var newMenu = Obj.menu;
var newContent = Obj.content;
// 1. compare current and new values. Store needed changes in queueArray
var queueArray = new Array();
if (newSection != '' && newSection != undefined && newSection != null && UI.section != newSection) {
UI.section = newSection;
queueArray.push('section');
}
if (newSortBy != '' && newSortBy != undefined && newSortBy != null && UI.sortBy != newSortBy) {
UI.sortBy = newSortBy;
queueArray.push('sortBy');
}
//etc , etc...
};
});<br clear="all">
Thank you for your time !
--
Alexandre