I am getting several 'undefined' errors when running this code in JSHint:
MERLIN.namespace('MERLIN.http');
MERLIN.http = function ($, window) {
'use strict';
// import dependencies
function request(config) {
if (!config || typeof config !== 'object') {
return;
}
// perform request
$.ajax({
type: config.type || 'GET',
url: config.url,
dataType: config.dataType,
data: config.data || {},
processData: config.process || false,
beforeSend: function () {
indicator(config.panel, config.indicator);
},
complete: function () {
indicator(config.panel, config.indicator);
},
success: function (resp) {
var callback = config.success || null;
if (typeof callback !== 'function') {
callback = false;
}
if (callback) {
callback.apply(this, [resp]);
}
},
error: function (xhr, textStatus, errorThrown) {
httpError({
xhr: xhr,
status: textStatus,
error: errorThrown,
panel: config.panel
});
}
});
};
function indicator(panel, type) {
if ((!panel || typeof panel !== 'string') || (!type || typeof type !== 'string')) {
return;
}
var indicatorType = (type === 'large') ? type = 'indicatorLarge' : type = 'indicatorSmall';
return $(panel).toggleClass(indicatorType);
};
function httpError() {
return this;
};
return {
request: request,
error: httpError
};
} (jQuery, this);
I am not sure why the undefined errors are being thrown for 'indicator' and 'httpError' and why the use of 'return this' is a potential strict violation. I know I can safely ignore the undefined error relating to the namespace as the general purpose namespace function is defined earlier in a separate file.
Is it just a case of pragmatism versus strict validation?
Thanks :)