I am working on a js code snippet to make a function which can be called with object literal.
Problem area : If i do not need to track the product value then a check has been placed for undefined. But do i really need to make check for each & every value if its not there in the object literal. Below is the code.
trackProduct = function (args) {
if(args.label == undefined) {
value.push([args.category, args.action, args.value]);
} else if(args.value == undefined){
value.push([args.category, args.action, args.label]);
} else {
value.push([args.category, args.action, args.label, args.value]);
}
};
Calling this function via below object literal. I have not passed the value parameter.
trackProduct({
category: elemcategory,
action: elemaction,
label: elemlabel
});
Do we need to check for Undefined for all three paramters? Any suggestions on how to improve this code.
value.push( args )– Esailija Nov 21 '12 at 10:44