JSFiddle - React, Tailwind, and code Playground
HTML
<div onClick="func()">click me to trigger
</div>
JavaScript
document.func = function() {
var businessLine1 = {
id: 1,
text: 'abcd'
}
var businessLine2 = {
id:2,
text: 'efgh'
}
var obj = function(){
this.a = 1;
this.b = 2;
this.BusinessLine = businessLine1;
this.c = 3;
};
obj.prototype = {
clone: function () {
return $.extend({}, this);
},
loadClone: function (clone) {
var self = this;
$.each(self, function (index, value) {
self[index] = clone[index];
});
}
};
var obj1 = new obj();
var obj2 = obj1.clone();
obj2.BusinessLine = businessLine2;
console.log(obj2.BusinessLine); // businessLine2
console.log(obj1, obj2); // businessLine1, businessLine1
obj2.loadClone(obj1); //irrelevant
console.log(obj1, obj2);
}