Question

In many languages such as C++,main() function is the first function which is executed first when the program is run so is there any way to tell javascript to execute any function first.

i tried to find on internet but i get only this topic on stack overflow and all other sites were just explaining the same thing about a function, its argument, callbacks.. and so on

In the above link that person was using the ajax but i dont want to use ajax and those answer were not satisfactory to me.

In this question too, is asked is there in any main function in javascript. But in this too the answers tells that there is no such type of function but do not is tell about a function that can do same this and also @FishBasketGordo tell that user defines then i want that function

What is that function?

my purpose:

var varlist = {};

now i will add all my variables like a object property in that object and when there will all the variable those variable be saved by javascript and this will solve the problem in javascript that all the variable should be defined at the top

please help me to short out this problem

thanks

Était-ce utile?

La solution

Javascript functions are invoked in only two ways in browsers:

  1. They are explicitly invoked, within a <script> tag.

  2. They are invoked as the callback of an event handler

(or they are called by other functions, with the chain of function calls resulting from one of the two cases above)

In the former case, order of execution is controlled by the order of the <script> tags, so the first function called will be the first function invocation (if any) found in those tags.

The only event that'll happen automatically as the page is loaded is the window.onload event, so you can use that if you prefer instead of making an explicit function call.

In other words, order of execution is completely up to you.

There is no main function.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top