javascript / beginner
Snippet
The constructor Method
The constructor is a special JavaScript function that runs automatically when a new instance of a class is created. It is often used for initial setup.
snippet.js
javascript
1
2
3
4
5
6
7
export class UserComponent {status = 'offline';constructor() {this.status = 'online';}}
angular
Breakdown
1
constructor() { ... }
A standard method used to initialize class properties.
2
this.status = 'online'
The 'this' keyword refers to the current class instance.