Open johnhill396 opened 3 weeks ago
I'm pretty sure this is okay.
It is ok. But you should note that this
is not initialized at this moment.
It is ok. But you should note that
this
is not initialized at this moment.
yeah, that's what I was worried about. Could that cause any issues at runtime? Any best practices around it?
You can just use this as alterative:
class MyContext {
somethingObj: Something!; // use exclamation mark
constructor() {
this.somethingObj = new Something(this)
}
myMethod(): void {
this.somethingObj.testMethod()
}
}
Question
I'm working on an AssemblyScript application. The way the code is structured requires passing an instance of a class in the constructor of another class. For example:
I'm able to build and run the code successfully. But, is the above field somethingObj in MyContext class correctly using 'this' keyword? Could this somehow lead to some runtime errors around out of bounds memory access?