I was going through this code, and on this line I saw
(window).user = user;
I am wondering what is the importance of setting the user object as a value in the window object? I understand it may be for easier access in the future, but the user object is also stored in an observable and the get user() method retrieves it from the observable:
getUser(): Observable<any> {
return this.$userSource.asObservable();
}
Also from this answer I understand that:
In JavaScript, any global variable is actually a property of the window object. Using one is equivalent to (and interchangeable with) using the other.
So my questions are:
- What is the importance of setting the user object as a value in the window object?
- Will the code still function well if we got rid of the line storing the code in the window object?
- Are the global variables in typescript classes the same as the property of the window object? For example: Is this value also a property of the window object?