JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<div id="btn">
test
</div>
JavaScript
var deepExtend = function(target, ...sources) {
var isObject = function(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
if (!sources.length) return target;
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
deepExtend(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return deepExtend(target, ...sources);
}
var a = {
construct: function() {
this.$modal = ( $('#modal') );
},
foo: {
func1: function() {
console.log(1)
},
func2: function() {
console.log(2);
}
}
}
var b = {
foo: {
func3: function() {
console.log(3)
}
},
jqueryprop: $('#btn')
}
deepExtend(a, b);