Elegant way of processing an "options" parameter In this constructor function I'm assigning everything to the proper variables. For the third parameter it accepts an options argument that contains the optional settings.

To prevent a Cannot read property x of undefined. error I'm always checking this variable by steps, since the options variable can contain both complex objects and primitive data types.

I'm wondering if there is a more elegant way I could write this?

Constructor

function LiveDate(timeUrl, element, options) {
    this.timeUrl = timeUrl;
    this.element = element;

    this.format = options &amp;&amp; options.format ? options.format : LiveDate.formats.ISO8601;
    this.offset = options &amp;&amp; options.offset ? options.offset : 0;

    this.weekdayNames = {
        long: options &amp;&amp; options.weekdayNames &amp;&amp;  options.weekdayNames.long ? options.weekdayNames.long : [
            'Sunday',
            'Monday',
            'Tuesday',
            'Wednesday',
            'Thursday',
            'Friday',
            'Saturday'
        ],
        short: options &amp;&amp; options.weekdayNames &amp;&amp; options.weekdayNames.short ? options.weekdayNames.short : [
            'Sun',
            'Mon',
            'Tue',
            'Wed',
            'Thu',
            'Fri',
            'Sat'
        ]
    };

    this.monthNames = {
        long: options &amp;&amp; options.monthNames &amp;&amp; options.monthNames.long ? options.monthNames.long : [
            'January',
            'February',
            'March',
            'April',
            'May',
            'June',
            'July',
            'August',
            'September',
            'October',
            'November',
            'December'
        ],
        short: options &amp;&amp; options.monthNames &amp;&amp; options.monthNames.short ? options.monthNames.short : [
            'Jan',
            'Feb',
            'Mar',
            'Apr',
            'May',
            'Jun',
            'Jul',
            'Aug',
            'Sep',
            'Oct',
            'Nov',
            'Dec'
        ]
    };

    this.start();
}
You could do something like this to clean things up a little:

options = options || {};

// Set to Default values first
this.weekdayNames = {
  "long": [...],
  "short": [...]
};

// Then check to see if we need to override
if ( options.weekdayNames ){
  for ( var key in options.weekdayNames ){
    this.weekdayNames[ key ] = options.weekdayNames[ key ];
  }
}


Furthermore, something like lodash's defaults function https://lodash.com/docs#defaults may be of use.