JavaScript Definitive Guide, chapter 3rd several concepts

Source: Internet
Author: User

A function is a special object;

Object: A collection of properties (name-value pairs);

The function is used to initialize (with the new operator) a newly created object is called a constructor.

The object is called as a method when the property is a function.

Within a function body, a local variable takes precedence over a global variable of the same name.

code example:

var                 scope = "global"; // Declare a global variable

functionCheckscope () {
varScope = "local";//life a local variable with the same name
returnScope//The value of the local variable is returned, not the value of the global variable
}
Checkscope ()//Local

Note that Var is not written before global variables, but must be written before local variables.


Declaration in advance (hositing) code example:

var scope = "global"; function f () {//should be Var Scope;var advance to thisConsole.log (scope); Output undefined, not "global"var scope = "local"; (scope = "local") var advance the variable in this assignment, but the variable itself is defined in the function body.Console.log (scope); Output "local"}


A scope chain is either an object list or a linked table. This set of objects defines the variables in the scope of this code. ( still not quite understand, to be solved )

JavaScript Definitive Guide, chapter 3rd several concepts

Related Article

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.