Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  135] [ 2]  / answers: 1 / hits: 18635  / 10 Years ago, tue, august 12, 2014, 12:00:00

I've started to write code in TypeScript for 3 days. I have completed all my class designs but at this point I'm writing the main function. Everything is nice but somebody have to run the Main() function. I do this with this way;




  • by calling directly Main();



I'm just curious about that is there any method which is not triggered by me ? or How do you handle your Main() methods when typing your code in TypeScript?


More From » typescript

 Answers
40

Unlike class-based languages, JavaScript does not require a main method.



Since TypeScript is a super-set of JavaScript, all JavaScript code is also valid TypeScript, and therefore doesn't need a main.



So, you can call your Object (JavaScript) or Class (TypeScript) anything you'd like -- Main, DoThis or even ServeMeADrink and all are equally valid and can be invoked by calling, just as you've done.



They can also be invoked by:




  • event handlers

  • A framework's system, such as the data-main attribute used by some MVC/JavaScript systems.


[#69809] Sunday, August 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katia

Total Points: 570
Total Questions: 101
Total Answers: 85

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;