Getting some trouble to do the following in typescript. I've the following interface defined :
interface RendererCallback {
getNode():HTMLElement;
getTable();
}
There is a method expecting a RenderCallback object like :
render( callback:RendererCallback )
How do I create an anonymous instance in the middle of my code :
myObject.render( new .. {
getNode() {
return myNode;
}
getTable() {
.. some code...
return something;
}
} );
You can use anonymous objects and lambdas:
myObject.render({
getNode: () => { doSomething...; return myNode },
getTable: () => myTable
});
Note, the new
keyword is not used.
Typescript now supports class expressions so you can make actual anonymous classes.
myObject.render( new class {
getNode() {
return myNode;
}
getTable() {
.. some code...
return something;
}
} );
This has the benefit of this
not being inferred to be any
within the anonymous class' methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With