Task: I need to build a class in Typescript that calls some of it's own methods in it's own Constructor.
Problem: The Actual Code that the following Sample Code represents will Compile Successfully, but upon testing in the Javascript Console, it does not.
Sample:
export class volumeEQ
{
constructor(ctx:any)
{
this.ctx = ctx; // Audio context saved into member variable of class
this.setupAudioNodes(); // Sets up nodes made out of audio
}
setupAudioNodes()
{
this.sourceNode.connect(this.ctx.destination); // Connect to destination
}
}
Technical: The Typescript Compiler does not have a problem with this.setupAudioNodes()
but once called as Javascript within the Browser's Javascript Console I receive an error Uncaught TypeError: undefined is not a function
. Effectively, this is an issue with Javascript's this.
syntax and how it's easy to get confused with it. But because I'm developing in Typescript, I want a more Typescript style solution.
Question: How can I call a Class's Methods from it's Constructor in Typescript?