1. Accessing literals and local variables is the fastest, while accessing array elements and object members is relatively slow. When accessing an object member, the prototype chain is searched, just like the scope chain. 2. If the member found is too deep in the prototype chain, access speed will be slow. So try to minimize the number of searches and nesting depth of object members. Examples// Perform two object member searches function hasEitherClass(element, className1, className2) { return element.className === className1 || element.className === className2; } //Optimization, if the variable does not change, you can use a local variable to save the search content function hasEitherClass(element, className1, className2) { const currentClassName = element.className; return currentClassName === className1 || currentClassName === className2; } Content extension: js object operation performance issues 1 The longer the string is, the time it takes to use str+="xxx" will increase significantly (almost exponentially). 2 When the object array has only 400 elements, the access time to the properties and methods of each element reaches 1/4 millisecond for each property or method! If an element has 10 attributes, then a traversal of the array will take at least 1 second, which is terrible. 3 FileSystem operations, especially write operations, are almost proportional to the square of the length of the string to be written. 4 Do not use your own methods to perform string operations, especially replacement, search, and comparison; I don't have a good grasp of regular expressions. When using custom functions, I found that in the traversal mentioned in 2) above, The custom function takes up to 80% of the total time! This concludes this article on the detailed example of js object reading speed. For more information about js object reading speed, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed tutorial on installing Hbase 2.3.5 on Vmware + Ubuntu18.04
>>: Web developers are concerned about the coexistence of IE7 and IE8
First of all, you can understand the difference b...
Preface In daily work, we sometimes run slow quer...
When you log in to MySQL remotely, the account yo...
The plugin is installed in the Firefox browser. T...
Vue router transitions are a quick and easy way t...
Preface All hardware devices in the Linux system ...
Table of contents 1. Nodes, trees, and virtual DO...
Application scenario 1: Domain name-based redirec...
Problem to be solved Mainly for cross-level commu...
1: nginx server solution, modify the .conf config...
Table of contents Make scrolling smoother BetterS...
This article mainly explains tables, which are no...
Today when I was writing a flash advertising code,...
#String concatenation concat(s1,s2); concatenate ...
Table of contents Time zone configuration in Djan...