I have a little class that extends the Date object in JavaScript. One method just returns the current Date in UTC.
Date.prototype.nowUTC = function(options) {
var now = new Date();
return new Date(now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours(),
now.getUTCMinutes(),
now.getUTCSeconds());
}
What I'd like to do is define the options parameter as an object that will contain hours, minutes, and seconds, which will be added to the time. For example,
Date.prototype.nowUTC = function(options) {
var now = new Date();
return new Date(now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate(),
now.getUTCHours() + options.hours,
now.getUTCMinutes() + options.minutes,
now.getUTCSeconds()) + options.seconds;
}
Is there a way to pre-define these values, so I don't have to check if it's defined before adding it or set a default? (such as function(options = {'hours' : null, 'minutes' : null, 'seconds' : null) {}
) Id prefer to handle the parmeter like - as one object - instead of passing separate params for each value.
Thank you!