Is it possible to create a class that instantiates functions with methods on it's prototype? I am trying to convert code from prototype structure to using the es6 class syntax. Here is a contrived and over simplified example of the starting point
function createFun(init) {
function fun(newDats) {
this.data = newDats;
// create universe
}
function internalMethod() {
}
fun.data = init;
fun.aMethod = function () {
internalMethod();
}
assign(fun, AnExtendableClass.prototype);
return fun;
}
// and can be used as such
fun = createFun('first');
fun('second');
fun.aMethod();
fun.methodFromExtendableClass('third')
And this is what I have tried
class Fun extend AnExtendableClass {
constructor(init) {
super();
this.data = init;
function fun(newDats) {
this.data = newDatas;
//create universe
}
assign(fun, this);
return fun;
}
aMethod() {
}
}
Unfortunately this does not work and function with no methods in return.