I'm currently working with a JavaScript code snippet that looks like the example below. On this particular line,
this.orgBusinessKey = this.user.noaOrganisationList[0].businessKey;
I'm wondering if the this
scope will contain the user
instance that is passed as a parameter to the constructor.
While I have already checked out this article on this
scope, but I still have doubts. In my understanding, at setAdmin
, does this
point to MyClass
, which may not include the parameters like user
from the constructor?
export interface IUser {
noaOrganisationList: IOrganisation[];
}
export interface IOrganisation {
id?: number;
name?: string;
businessKey: string;
}
export class MyClass {
orgBusinessKey: string = '';
constructor(public user: IUser)
{
this.setAdmin(user);
}
setAdmin(user: IUser): void {
if (user && user.noaOrganisationList && !_.isEmpty(user.noaOrganisationList)) {
this.orgBusinessKey = this.user.noaOrganisationList[0].businessKey;
}
}
}