Hello everybody!
Would it be faster to just put code inside a try-catch block instead of performing various error checks?
For example..
function getProjectTask(projectTaskId) {
if (YAHOO.lang.isUndefined(projectTaskId) || YAHOO.lang.isNull(projectTaskId) && !YAHOO.lang.isNumber(projectTaskId)) {
return null;
}
var projectPhaseId, projectPhaseIndex, projectTaskIndex, projectPhases, projectPhase, projectTask;
if (!YAHOO.lang.hasOwnProperty(projectTaskPhaseMap, projectTaskId)) {
return null;
}
projectPhaseId = projectTaskPhaseMap[projectTaskId];
if (YAHOO.lang.isUndefined(projectPhaseId) || YAHOO.lang.isNull(projectPhaseId) || !YAHOO.lang.hasOwnProperty(scheduleData.ProjectPhasesMap, projectPhaseId)) {
return null;
}
projectPhaseIndex = scheduleData.ProjectPhasesMap[projectPhaseId];
if (YAHOO.lang.isUndefined(projectPhaseIndex) || YAHOO.lang.isNull(projectPhaseIndex) || !YAHOO.lang.hasOwnProperty(scheduleData.ProjectPhases[projectPhaseIndex])) {
return null;
}
projectPhase = scheduleData.ProjectPhases[projectPhaseIndex];
if (!YAHOO.lang.hasOwnProperty(projectPhase.ProjectTasksMap, projectTaskId)) {
return null;
}
projectTaskIndex = projectPhase.ProjectTasksMap[projectTaskId];
if (YAHOO.lang.isUndefined(projectTaskIndex) || YAHOO.lang.isNull(projectTaskIndex)) {
return null;
}
projectTask = scheduleData.ProjectTasks[projectTaskIndex];
}
VS
function getProjectTask(projectTaskId) {
try {
projectPhaseId = projectTaskPhaseMap[projectTaskId];
projectPhaseIndex = scheduleData.ProjectPhasesMap[projectPhaseId];
projectPhase = scheduleData.ProjectPhases[projectPhaseIndex];
projectTaskIndex = projectPhase.ProjectTasksMap[projectTaskId];
projectTask = scheduleData.ProjectTasks[projectTaskIndex];
}
catch (e) {
return null;
}
}
I hope my question makes sense. I would be happy to clarify. Thank you!