当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript效率调优经验

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JavaScript效率调优经验


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 363 ::
收藏到网摘: n/a

有时候大家在使用多字符的时候,需要用的到下面的知识。 1. 将循环次数的定义放到循环体外:这点好像所有的语言都是一样的,在100个元素以上时效果越来越明显。也就是说将for(var i=0;i<arrData.length;i++)修改为for(var i=0,len=arrData.length;i<len;i++)会很大地提高性能,因为它避免了每循环一次计算一下length的操作。另外,有老外宣称,降序循环速度更快,即for(var i=arrData.length-1;i>=0;i--)。本人测试后发现和升序循环相比效率差异不大。
2. 将多层对象引用改为更短路径的引用:JavaScript中,这个问题非常明显,如proposalNo域var proposalNoField = fm.proposalNo。在一个循环中(100次以上)使用proposalNoField.value和fm.proposalNo.value的区别非常巨大。所以尽量通过使用中间变量的方式来缩短访问路径。
3. 第三方JavaScript包的影响:由于JavaScript支持原型,如prototype.js就修改了Array的一些行为,有时自己写的代码是没有问题的,但是如果被修改了原型,则也会发生问题,如prototype.js的1.4版本就存在Bug,某些情况下的数组排序会导致死循环。