object) is automatically created, and a scope chain (scope Chain) is bound at the same time. The scope chain is established using the following two steps for identifier resolution.
The objects in the internal properties of the function object [[Scope]] are first copied to the scope chain in order.
Second, when the function executes, a new activation object is created that contains the definition of this, parameters (arguments), local variables (including named arguments), and this
Global Object
The global object is the most specific object in the ECMAScript because it does not actually exist at all. If you try to write the following code, you get an error:
The error message shows that global is not an object, but was it not that
Javascript (2) Global object usage1. Global Object: All attributes and methods defined in the Global scope are Global object attributes.2. The Global object is not directly used and cannot be created using the new operator. It is
when using eval to execute user input content, it may be injected by code.
All attributes of the Global ObjectGlobal does not only have methods, but also has all attributes of the Global object:
Attribute
Description
Undefined
Undifined literal
NaN
Non-numeric value
Infinity
Special Value of an infinite value
Object
Object constructor
Arr
(){Return value;}}}
Var myAccount = bankAccount (); // create a new bank accountMyAccount. deposit (1000); // store 1000 piecesAlert (myAccount. getValue (); // shocould alert (1000 );
Value in the function bankAccount, external operations cannot be performed on it directly. Therefore, you must use the function of bankAccount to operate on the objects returned by it, in this way, the private fields in C # and java are implemented.
Slowing down global
attributes of the Global Object
Global does not only have methods, but also has all attributes of the global object:
Attribute
Description
Undefined
UndifinedType literal
Nan
Non-numeric value
Infinity
Special Value of an infinite value
Object
ObjectConstructor
Array
Javascript (2) Global object usage, javascriptglobal1. Global Object: All attributes and methods defined in the Global scope are Global object attributes.2. The Global object is not directly used and cannot be created using the ne
value;}}}Var myAccount = bankAccount (); // create a new bank accountMyAccount. deposit (1000); // store 1000 piecesAlert (myAccount. getValue (); // shocould alert (1000 ); Value in the function bankAccount, external operations cannot be performed on it directly. Therefore, you must use the function of bankAccount to operate on the objects returned by it, in this way, the private fields in C # and java are implemented.Slowing down global variable po
execute user input content, it may be injected by code.All attributes of the Global ObjectGlobal does not only have methods, but also has all attributes of the Global object:
Attribute
Description
Undefined
UndifinedType literal
NaN
Non-numeric value
Infinity
Special Value of an infinite value
Object
ObjectConstructor
Array
ArrayConstr
See the following code:This code is actually about how JavaScript creates a private variable and a private method. This is not a big problem. It should be noted that, after entering the class, the private methods of the class can use the private variables of the class, which are layered and interesting. The use of global variables in private methods of classes is also normal and there is no suspense. The pu
want. The error is prompted in the console console:Uncaught Referenceerror:num is not defined If you omit the var operator, then the variable is a global variable. So, we get rid of the test:function Add () { num=5; Console.log (num); } alert (num);At this time, found the console prompted the same error as above!!What is this for?With a closer l
This article mainly introduces the differences between Javascript global variables var and non-var. For more information, see global variables, variables defined in the form of a = 1 in the function scope will be a global variable. In the global scope, you can create globall
the error things
}
}
But remember I said that browsers are event-driven? Yes, an exception in JavaScript is just an event. The interpreter stops the program at the current context where the exception occurred and throws an exception. To confirm this, here is a global event handler function onerror that we can se
newly created error type
Browsers treat custom error types that inherit from error, just as they do with other types of errors. It is useful to create a custom error if you want to catch your own thrown error and treat it differently from a browser
I. Classification of Errors
1, syntax error: Also known as parsing errors, occurs in the traditional language of the compilation, in JavaScript occurs in the interpretation. These errors are caused directly by unexpected characters in the code, and then cannot be compiled/interpreted directly. You cannot continue executing code when a syntax error occurs. In
threads can continue to perform normally.Two Handling Errors1. OnError event handler functionIt is the first mechanism to assist JavaScript in handling errors. When an exception occurs on the page, the error event fires on the Window object. Eg.In the preceding code, an exception is thrown when a page load is attempted to invoke a function that does not exist. A
22. Error handling
1, Prohibit JS error (suppress JS Errors)
Q: Can i disable JavaScript error messages?
A: That 's OK. To disable all JavaScript error messages on the page, you should put the following code in the Head section o
Customerror (' My message ');
When the throw statement is encountered, the code stops executing immediately. The code continues to execute only if a Try-catch statement captures the value being thrown
A more detailed explanation is that when an exception is thrown, the JavaScript interpreter immediately stops the currently executing logic and jumps to the nearest exception handler. The exception
22. Error Handling
1. Disable JS errors (Suppress JS errors)
Q:Can I disable javascript error messages?
A:Yes. To disable all JavaScript error messages on the page, you need to put the following code in the head part of the page:
Or you can use similar code in the. js fil
JavaScript binds this in a global function as a global object, and uses the same interpretation for nested functions. Let's look at a piece of JavaScript code nested with two-layer functions:
The Code is as follows:
Var me = {Name: 'jimbor ',Blog: 'http: // jmedia.cn /',SayMyName: function (){Var pre = 'My name is :
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.