+ 1
keyword constructor in typescript?
Hi all, I'm a "beginner" in typescript. I'm on constructors chapter.Please define what is a 'constructor in typescript' ?Also , easy to understand example ? Thanks
1 Odpowiedź
+ 2
A constructor in typescript (or javascript and many other OOP languages), is the method of a class that is called when an instance of the class is created.
class Example {
constructor(param: string) {
alert('received param: ' + param);
}
}
new Example('hello'); // alerts "received param: hello"