For years my focus has been server-side stuff, but I'm now being tasked with client-side. If anyone knows of some recognized best-practices guides, I'd love to read them. In addition, I'd appreciate hearing some comments on the following items I'm dealing with while trying to edit code written by someone else:
1. The javascript file I'm currently working with starts with the following. I'm only including the top for sake of size, and because this isn't a troubleshooting question (I'm adding functionality, not fixing problems), and because this region relates to my question, specifically:
So, if I'm reading this correctly, it starts by defining a variable, which is set to the value of a JSON object, whose 17th or so key:value pair is an array, each element of which is a JSON objcet, each of which contains at least one function. The array has at least 20 elements (I gave up counting after that), and there are more pairs after the array.
On this, I'm asking if this is the generally accepted way to write it? I find it nauseating to read. When I'm down to the 20th element of the array, the curly braces for functions and JSON data start to kind of run together. If nothing else, I guess it seems to negatively affect readability to write everything "inline." But, if this is just the way these things are done, I'll force myself to get used to it.
2. Is it common/recommended/accepted practice to preface the type before the variable name in camel case (ie. sTitle)? I never saw the c# devs I worked with do this, and I never do it. I usually only saw it this when editing other people's VB6 and VB.NET code.
1. The javascript file I'm currently working with starts with the following. I'm only including the top for sake of size, and because this isn't a troubleshooting question (I'm adding functionality, not fixing problems), and because this region relates to my question, specifically:
Code:
var _defaultSettings = {
iSelAllIndex: 0,
iDocTypeIndex: 2,
iUploadedByIndex: 4,
iIsNewDataIndex: 5,
iIsCompanyOnlyDataIndex: 6,
iFilesDataIndex: 8,
iHighlightDataIndex: 10,
oSettings: this,
newEntryImgHTML: "<img src=\"/images/New_icons_41.gif\" ></img>",
entryDownloadedImgHTML: "<img src=\"/images/checkmark.png\" ></img>",
downloadButtonImgHTML: "<img src=\"/images/download.gif\" ></img>",
CompanyOnlyHTML: "<img src=\"/images/Padlock.png\" ></img>",
"sGetEntryListService": "/Services/Secure/EntriesList.asmx/GetEntryListForJQueryDataTable",
"sGetDocTypesWithFilesUploadedService": "/Services/Secure/EntriesList.asmx/GetDocTypesWithFilesUploaded",
"sGetUploadedByUsersService": "/Services/Secure/EntriesList.asmx/GetUploadedByUsers",
"sPageSizeService": "/Services/Secure/EntriesList.asmx/GetOrSetEntryListSize",
"aoColumns": [{ sTitle: "Date", sName: "EntryDate", sWidth: "110px", bUseRendered: false,
fnRender: function (oObj) {
var str = oObj.aData[oObj.iDataColumn];
var isNew = oObj.aData[oSettings.iIsNewDataIndex];
var dateTime = new Date(parseInt(str.substr(6)));
var dateHtml = $.datepicker.formatDate("mm/dd/yy", dateTime);
if (isNew)
dateHtml = dateHtml + oSettings.newEntryImgHTML;
return "<span title=\"" + dateTime.toString() + "\">" + dateHtml + "</span>";
}
},
{ sTitle: "EntryType", sName: "EntryType", sWidth: "240px", bUseRendered: false,
fnRender: function (oObj) {
-----------------------------
So, if I'm reading this correctly, it starts by defining a variable, which is set to the value of a JSON object, whose 17th or so key:value pair is an array, each element of which is a JSON objcet, each of which contains at least one function. The array has at least 20 elements (I gave up counting after that), and there are more pairs after the array.
On this, I'm asking if this is the generally accepted way to write it? I find it nauseating to read. When I'm down to the 20th element of the array, the curly braces for functions and JSON data start to kind of run together. If nothing else, I guess it seems to negatively affect readability to write everything "inline." But, if this is just the way these things are done, I'll force myself to get used to it.
2. Is it common/recommended/accepted practice to preface the type before the variable name in camel case (ie. sTitle)? I never saw the c# devs I worked with do this, and I never do it. I usually only saw it this when editing other people's VB6 and VB.NET code.