javascript - What is lexical scope? -


Can someone please give me a brief introduction to literally scoping?

I understand them through examples :)

  zero Fun () {int x = 5; Firstly, lexical scope (also called static scope), in C-syntax:  
 zero fun 2 () {printf ("% d", x);  

Every internal level can reach its external level.

There is another way called the dynamic scope used by the first execution of Lisp, again in the C-syntax:

  zero fun () {printf (" % D ", x); } Zero dummy 1 () {int x = 5; Fun (); } Zero dummy 2 () {int x = 10; Fun (); }  

here funny in either x in dummy1 or dummy2 Can enter or x has been declared with funny in any function x .

  dummy1 ();  

will print 5,

  dummy2 ();  

10 will be printed.

The first is called static because it can be estimated at compiled time, the second is called dynamic because the outer radius is dynamic and the function's chain depends on the call.

I find scoping static easy for the eye. In most languages ​​this way, finally, lisp (both, right?), Dynamic scoping is to send all the functions into a function referred to.

An example of this example is that the compiler can not remove the external dynamic scope of a function, if we write something like this, then consider our last example:

if (/ * certain condition * /) dummy 1 (); Second dummy 2 ();

The call series depends on a run time condition. If this is true, the call series looks like this:

  Dummy 1 -> Funny ()  

If the situation is false:

  Dummy 2 -> Funny ()  

In both cases the fun is external circle collar plus collar collar and so on .

Nested functions and dynamic skoping are not allowed to just mention that language.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -