Is it a bad practice to return a class inside the method of another class?
Example: createBlockClass method
class BlockBuilder {
constructor (methodForBlock) {
this.methodForBlock = methodForBlock;
};
createBlockClass () {
const method = this.methodForBlock.bind(this.methodForBlock);
return class Block {
constructor(title) {
this.title = title;
};
method = method;
}
}
};
const blockBuilder = new BlockBuilder(() => console.log('Hello, world!!!'));
const Block = blockBuilder.createBlockClass();
const block1 = new Block("block one");
const block2 = new Block("block two");
block1.method();
block2.method();
I need to receive a method as a parameter and add it to the block class before creating any instance
Via Active questions tagged javascript - Stack Overflow https://ift.tt/grMIEFY
Comments
Post a Comment