随着实际应用中JavaScript程序的复杂度日益提高,程序执行的性能问题变得突出,而优化JavaScript程序中数组的使用方式可以提高程序效率。通过分析JavaScript数组的特点,结合广泛应用的Chrome V8引擎的源程序,描述V8对JavaScript数组的实现细节,重点分析Fast Elements和Dictionary Elements两种数组存储模式,给出对JavaScript数组性能优化的基本原则,并举例分析4个实际应用中可以优化的程序片段。%With the complexity of JavaScript applications increasing, performance issues of JavaScript become increasingly promi-nent, but to optimize the use of JavaScript array can improve program efficiency.This paper, by analyzing the characteristics of JavaScript arrays and reviewing the source code of Chrome V8 JavaScript engine, describes the implementation details for JavaS-cript array in V8, and focuses on the Fast Elements and Dictionary Elements array storage modes.It also gives the basic princi-ples of performance optimization of JavaScript array and four examples to show how to analyze and optimize programs in practical applications.
展开▼