I've come across a code similar to the one below on several occasions recently.
One thing to observe is that modelMapper
, viewMapper
, and source
are all defined as local variables but are not used anywhere else, except for being keys in the return object.
An interesting point to mention is that $parse
returns a function, and only keys related to a returned function are declared as local variables - itemName
is an exception.
parse:function (input) {
var match = input.match(TYPEAHEAD_REGEXP), modelMapper, viewMapper, source;
if (!match) {
throw new Error("Error...");
}
return {
itemName:match[3],
source:$parse(match[4]),
viewMapper:$parse(match[2] || match[1]),
modelMapper:$parse(match[1])
};
}
What is the significance of defining these local variables?