In-depth understanding of javascript--notes

Source: Internet
Author: User

Write maintainable code

1, the minimum global variable can be used directly in JS without declaring the variable, so be careful not to use it without declaring it. (a global variable created unintentionally) such as a VAR declaration using a task chain. var a=b=12; the correct notation is var a,b;a=b=12; Technically, an implicit global variable is not a real global variable. Variables declared with Var can be deleted with the delete operator, but implicit global variables are not allowed, only one property of the global object. Properties can be deleted, variables are not available.

for---in traversal on non-array objects, also called enumerations. Although arrays are also objects in JavaScript, it is not recommended to use for--in--to iterate through arrays. There is an important way hasownproperty () can filter out attributes or methods inherited from the prototype chain. Avoid using eval () in JS, SetTimeout (); SetintervaL (); Function ();

//Reverse Example
setTimeout ("MyFunc ()", +);
setTimeout ("MyFunc (1, 2, 3)", +);

//Better
SetTimeout (MyFunc, +);
setTimeout (function () {
MyFunc (1, 2, 3);
}, +);


JS in the common self-executing function of the notation, 1. (function () {}) (); 2. (function () {} ()); 3,!function () {} (); 4,void function () {} ();

Return has an implicit semicolon, so when you write, if you return an object, the return is a line of curly braces.

The implementation of the inheritance between JS objects: Var a={say:function () {}};var b={__proto__: A};b inherits the methods and properties of a, and also has the Say method;

Before executing a piece of code, the browser will do some preparatory work. For example, the declaration of a variable, the assignment of this, is treated like a variable declaration for a function expression, and the function declaration is assigned directly to the function name. These three kinds of data preparation are referred to as the "execution context" or "execution context".

There are three types of code in ECMAScript, Function,eval,global

In-depth understanding of javascript--notes

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.