易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript 优化


Optimizing JavaScript code
Authors: Gregory Baker, Software Engineer on GMail & Erik Arvidsson, Software Engineer on Google Chrome
Recommended experience: Working knowledge of JavaScript
Client-side
scripting can make your application dynamic and active, but the
browser's interpretation of this code can itself introduce
inefficiencies, and the performance of different constructs varies from
client to client. Here we discuss a few tips and best practices to
optimize your JavaScript code.
Working with strings
String
concatenation causes major problems with Internet Explorer 6 and 7
garbage collection performance. Although these issues have been
addressed in Internet Explorer 8 -- concatenating is actually slightly more
efficient on IE8 and other non-IE browsers such as Chrome -- if a
significant portion of your user population uses Internet Explorer 6 or
7, you should pay serious attention to the way you build your strings.
Consider this example:
var veryLongMessage =
'This is a long string that due to our strict line length limit of' +
maxCharsPerLine +
' characters per line must be wrapped. ' +
percentWhoDislike +
'% of engineers dislike this rule. The line length limit is for ' +
' style purposes, but we don't want it to have a performance impact.' +
' So the question is how should we do the wrapping?';
Instead of concatenation, try using a join:
var veryLongMessage =
['This is a long string that due to our strict line length limit of',
maxCharsPerLine,
' characters per line must be wrapped. ',
percentWhoDislike,
'% of engineers dislike this rule. The line length limit is for ',
' style purposes, but we don't want it to have a performance impact.',
' So the question is how should we do the wrapping?'
].join();
Similarly,
building up a string across conditional statements and/or loops by
using concatenation can be very inefficient. The wrong way:
var fibonacciStr = 'First 20 Fibonacci Numbers
';
for (var i = 0; i < 2


相关文档:

基于javascript的用户登录页面验证

1,用户名不能包含空格,第一个字母不能为数字,长度控制
2,密码和验证码要相同,不能为空,等等,一些很基本的功能,但是确实挺烦人的。
      javascript调试起来确实比较麻烦。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<T ......

JavaScript中的剪贴板(clipboardData)

JavaScript中的剪贴板(clipboardData)
clipboardData 对象
提供了对剪贴板的访问。
三个方法
1.clearData(sDataFormat) 删除剪贴板中指定格式的数据。
2.getData(sDataFormat) 从剪贴板获取指定格式的数据。
3.setData(sDataFormat, sData) 给剪贴板赋予指定格式的数据。返回 true 表示操作成功。
例子
<script ......

IE与Firefox下javascript getyear年份的兼容性写法

                    前几天在测试网站兼容性问题,发现原来在IE下面正常的显示时间在Firefox获取年份下显示109
                &nb ......

Javascript操作Select和Option

注意:Option中的O是要大写的,不然语法报错
1.动态创建select
      function createSelect(){
var mySelect = document.createElement("select");
          mySelect.id = "mySelect"; 
        ......

优化JavaScript代码

我google一下,已有人翻译了此文.感觉比我翻译的要好!是译言站翻译的
见www.yeeyan.com/articles/view/92135/47626/dz
原文见:http://code.google.com/intl/zh-CN/speed/articles/optimizing-javascript.html
不合适的地方,请大家指出来!希望对你有用!
          &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号