What is the global scope of the <script> tag?

I made a flag and made my previous question deleted due to a misunderstanding.

I am working on a classic asp project.

let's say you have so many <script></script> tags in your code.

For instance:

line 10: <script> ..function 1 definition here..</script>

line 200: <script> .. function 2 definition here..</script>

line 5000: <script> ..function 3 definition here..</script>

also on line 6000: I have another tag that is trying to call function1.

maybe without using a * .js file?

For instance:

line 6000:

 <script> function1(); </script> 

These scripts are not defined in the <head> .

I know this is not useful, but I need to know if it has any way or not.

Hope it becomes clearer!

+4
source share
3 answers

all script tags are launched immediately. if you define function a() in the first element of the script, it will add a function called a to your global namespace. any javascript that you execute later in other script elements will have access to it.

 <script type="text/javascript"> function a() { alert('hi'); } </script> ... <script type="text/javascript"> a(); </script> 
+7
source

Yes, this is possible, assuming function1 is in a global scope (for example, not in a wrapper / self-starting function).

+2
source

Of course it is possible. You just need to define it in the global namespace. Here is a link that should give you an idea and a better understanding. It also includes very simple examples.

0
source

Source: https://habr.com/ru/post/1489948/


All Articles