You Don ' t Know Js:scope & Closures (try to translate)

Source: Internet
Author: User

Chapter 1:what is Scope?

Chapter One: What is a scope

One of the most fundamental paradigms of nearly all programming languages are the ability to store values in variables, and Later retrieve or modify those values. In fact, the ability to store values and pulling values out of variables are what gives a program state.

In almost all programming languages, it is one of the most basic abilities to store values in variables and later retrieve or change these values. In fact, this ability to store values into variables and remove values from variables gives the program "State".

Without such a concept, a program could perform some tasks, but they would is extremely limited and not terribly interesti Ng.

Without this concept, a program can accomplish some tasks, but they will have many places that are limited and not fun at all.

But the inclusion of variables to our program begets the most interesting questions we'll now address:where do those Variables Live? In other words, where is they stored? And, most importantly, how does we program find them when it needs them?

But the most interesting question that comes with the inclusion of variables in our program is: Where are these variables? Or, where are they stored? The most important thing is, when our program needs these variables, how does it find them?

These questions speak to the need for a well-defined set of rules for storing variables on some location, and for finding Those variables at a later time. We ll call that set of rules: Scope.

This problem requires a well-defined rule for storing variables in certain locations, and then finding these variables later, we can call this rule: scope

But, where and what do these Scope rules get set?

But where is the scope rule set? How is it set?

Compiler theory

Compilation principle

It may is self-evident, or it may is surprising, depending on your level of interaction with various languages, but despit E The fact that JavaScript falls under the general category of "dynamic" or "interpreted" languages, it's in fact a compi LED language. It is not compiled well in advance, as was many traditionally-compiled languages, nor is the results of Compilat Ion portable among various distributed systems.

This may be self-evident or may be surprising-depending on your ability to digest all languages, but although JS is a generic category of dynamic and interpretive languages, it is actually a compiled language. It is not compiled in advance because there are many traditional compiler languages that are not the product of a variety of distributed compilation systems.

But, nevertheless, the JavaScript engine performs many of the same steps, albeit in more sophisticated ways than we may co Mmonly be aware, the of any traditional language-compiler.

However, the JS engine also performs many of the same steps, although it uses a more complex approach than any traditional compiled language we might realize

In traditional compiled-language process, a chunk of source code, your program, would undergo typically three steps bef Ore it is executed, roughly called "compilation":

In the traditional process of compiling a language, a piece of source code, which is your program, will follow the typical ' three-step ', or ' compile ', before execution.

You Don ' t Know Js:scope & Closures (try to translate)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.