if ((typeof val === "object") && (val !== null)) { if (val instanceof Date) { var yyyy = val.getFullYear().toString(); var mm = (val.getMonth() + 1).toString(); // getMonth() is zero-based var dd = val.getDate().toString(); var HH = val.getHours().toString(); var MM = val.getMinutes().toString(); var SS = val.getSeconds().toString(); jsonval.value = (mm[1] ? mm : "0" + mm[0]) + '/' + (dd[1] ? dd : "0" + dd[0]) + '/' + yyyy + ' ' + (HH[1] ? HH : "0" + HH[0]) + ':' + (MM[1] ? MM : "0" + MM[0]) + ':' + (SS[1] ? SS : "0" + SS[0]); // padding } else { jsonval = val; } } else { jsonval = JSON.parse(val); }and this is a re-write by another colleague
if (_.isDate(val)) { jsonval.value = moment(val).format("MM/DD/YYYY HH:mm:ss"); } else if (_.isObjectLike(val)) { jsonval = val; } else { jsonval = JSON.parse(val); }which doesn't work. The val is passed as "7/10/2010" but the first check and the second check return false and then JSON.parse produces an error. Do you think instanceof is better to use?