JSFiddle - React, Tailwind, and code Playground
by jeanluca
JavaScript
function Foo() {
}
Foo.prototype.test = function(){ console.log('Foo'); } ;
function createAFoo(test) {
var newConst = (new Function( 'base', 'return function ' + Foo.name + '(){ base.apply(this, arguments); };'))(Foo) ;
newConst.prototype = new Foo() ;
newConst.prototype.test = test ;
return newConst ;
}
var NewFoo1 = createAFoo(function(){console.log('Foo1');})
, NewFoo2 = createAFoo(function(){console.log('Foo2');}) ;
new Foo().test() ;
new NewFoo1().test();
new NewFoo2().test();
console.log(new NewFoo1() instanceof Foo) ;