JSFiddle - React, Tailwind, and code Playground
by J Mac Lean
HTML
<div id="ContainerEl"></div>
JavaScript
function extendDefaults(source, properties) {
var property;
for (property in properties) {
if (properties.hasOwnProperty(property)) {
if (typeof properties[property] === 'object' && typeof properties[property].nodeType === 'undefined' ) {
extendDefaults(source[property], properties[property]);
} else {
source[property] = properties[property];
}
}
}
return source;
}
var myModule = function() {
// Define option defaults
var defaults = {
el: document.getElementById('ContainerEl'),
foo: 'bar',
bar: 'foo',
fooObject: {
option1: [],
option2: false,
option3: true,
option4: 'bar'
}
}
if (arguments[0] && typeof arguments[0] === "object") {
this.options = extendDefaults(defaults, arguments[0]);
}
}
var moduleInstance = new myModule({
foo: 'some value',
fooObject: {
option1: [1,2,3],
option2: 'bar'
}
});
console.log(moduleInstance);