A method of effectively improving data access speed in JS

Source: Internet
Author: User

hasOwnProperty () only retrieves the instance not to retrieve the prototype, in is to retrieve the instance, and retrieves the prototype

The deeper the member nesting, the slower the access speed, the use of object members only if necessary.

If you want to read the same object attribute multiple times in the same function, it is best to save it to a local variable. Replacing attributes with local variables avoids the performance overhead of redundant property lookups.

Direct and local variables are accessed very quickly, and array items and object members take longer.

A local variable is faster than an extraterritorial variable because it is in the first object in the scope chain. The deeper the position of a variable in the scope chain, the longer the time it takes to access it. Global variables are always the slowest because they are always in the last loop of the scope chain.

Avoid using the WITH expression because it changes the scope chain of the run-time context. The catch clause of the try-catch expression should be treated with care because it has the same effect

Nested object members can have a significant performance impact, with minimal effort.

In general, you can improve the performance of JavaScript code by storing the object members, array entries, and foreign variables that are often used in local variables. The local variables are then accessed faster than those of the original variables.

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.