Currently, I am working on a project using Ionic and Angular. I have come across various ways of instantiating variables and I'm unsure about the implications of each method. Here are three scenarios that confuse me:
export class someClass {
myVariable: string
...
someFunction() {
// How does this method of instantiation work?
this.myVariable = 'foo';
}
}
Does this just create a default string object that gets overwritten with "foo"?
export class someClass {
appService: AppService
constructor(appService: AppService) {
// How is this different from excluding it from the constructor?
this.appService = appService;
}
}
What does setting `this.appService` like this mean? Does it create duplicate instances?
export class someClass {
constructor(private storage: Storage) {}
async getSomeVariable(): Promise<any> {
// The parameter is mentioned in the constructor but not defined outside of it?
return await this.storage.get('someVariable');
}
}
Is a default instance of "Storage" created when done this way for later access in the function?