I'm going thru a tutorial and the author creates the properties of a class in the constructor. Is there a reason to do it this way instead of creating the properties in the class itself?
My background is C# so the reason why I would pass a parameter in the constructor is to make sure that when the class is instantiated, the arguments in the constructor are passed.
Here is the code that the author wrote:
export class Exercise {
constructor(
public name: string,
public title: string,
public description: string,
public image: string,
public nameSound?: string,
public procedure?: string,
public videos?: Array<string>
) {
}
}
This is the way that I create the class:
export class Exercise {
public name: string,
public title: string,
public description: string,
public image: string,
public nameSound?: string,
public procedure?: string,
public videos?: Array<string>
}