JSFiddle - React, Tailwind, and code Playground
by blesh
JavaScript
function Foo() {
}
Foo.prototype.betterSpawnClone = function (){
//create a copy of the current prototype.
var protoCopy = Foo.prototype;
//dynamically assign the prototype.
Foo.prototype = this;
//create the clone.
var clone = new Foo();
//reset the prototype back to normal.
Foo.prototype = protoCopy;
//return our clone.
return clone;
};
var foo = new Foo();
foo.bar = 'test';
var clone = foo.betterSpawnClone();
document.write(clone.bar);