Home > Web Front-end > JS Tutorial > JavaScript efficiency tuning experience_javascript skills

JavaScript efficiency tuning experience_javascript skills

WBOY
Release: 2016-05-16 18:51:49
Original
931 people have browsed it

1. Put the definition of the number of loops outside the loop: This seems to be the same in all languages, and the effect becomes more and more obvious when there are more than 100 elements. That is to say, for(var i=0;i=0;i--). After testing, I found that there is not much difference in efficiency compared to the ascending loop.
2. Change multi-layer object references to shorter path references: In JavaScript, this problem is very obvious, such as proposalNo field var proposalNoField = fm.proposalNo. The difference between using proposalNoField.value and fm.proposalNo.value in a loop (100+ times) is huge. So try to shorten the access path by using intermediate variables.
3. Impact of third-party JavaScript packages: Since JavaScript supports prototypes, such as prototype.js, it modifies some behaviors of Array. Sometimes there is no problem with the code you write, but if the prototype is modified, it will also happen. Problems, such as prototype.js version 1.4, have bugs, and array sorting in some cases can lead to an infinite loop.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template