+ 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

13th Jul 2019, 12:50 PM
swali1
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"
18th Jul 2019, 4:54 AM
JS Coder