JSFiddle - React, Tailwind, and code Playground
by Nuno Oliveira
JavaScript
function clone(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
var temp = obj.constructor();
for (var key in obj) {
temp[key] = cloneObject(obj[key]);
}
return temp;
}
function Parent(name) {
this.name = name;
}
Parent.prototype.sayHello = function() {
console.log('Hello my name is ' + this.name);
}
function Child(name) {
Parent.call(this, name);
}
Child.prototype = Object.create(Parent.prototype);
var child = new Child('Billy');
var clone = new Child();
for (var prop in child) {
clone[prop] = child[prop];
}
clone.name = 'Bob';
child.sayHello();
clone.sayHello();
console.log(child instanceof Child);
console.log(clone instanceof Child);