Javascript high-performance programming-improves data access speed and javascript high-performance

Source: Internet
Author: User

Javascript high-performance programming-improves data access speed and javascript high-performance
HasOwnProperty () Only retrieves instances without retrieving prototypes. in is the retrieval instance. The deeper the prototype member nesting, the slower the access speed. It only uses Object members when necessary. If you want to read the same object attribute multiple times in the same function, it is best to store it into a local variable. Replace attributes with local variables to avoid performance overhead caused by extra attribute searches. Direct Volume and local variable access speed is very fast, and it takes longer for Array items and object members. Local variables are faster than external variables because they are located in the first object of the scope chain. The deeper the location of a variable in the scope chain, the longer the access time. Global variables are always the slowest, because they are always at the end of the scope chain. Avoid using the with expression because it changes the scope chain of the runtime context. Also, you should be careful with the catch clause of the try-catch expression, because it has the same effect as nested object members will have a major performance impact and should be used as little as possible. In general, you can improve the performance of JavaScript code by storing frequently used object members, array items, and out-of-domain variables into local variables. Then, accessing local variables is faster than those of the original variables.

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.