JSFiddle - React, Tailwind, and code Playground
by jfriend00
JavaScript
function ValidDate(a,b,c,d,e,f,g) {
var date;
if (arguments.length === 0) {
// your special behavior here
date = new Date();
}
else if (arguments.length === 1) {
date = new Date(a);
} else {
c = c || 0;
d = d || 0;
e = e || 0;
f = f || 0;
g = g || 0;
date = new Date(a,b,c,d,e,f,g);
}
// add methods to this Date object
date.isValid = function() {
return !isNaN(this.getTime());
}
date.clone = function() {
return ValidDate(this.getTime());
}
return date;
}
var now = ValidDate(2014, 5, 8);
var then = now.clone();
console.log(now);
console.log(then);