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
文章标题:
javascript 字符串处理全攻略
关 键 字:
0
文章作者:
alonglee
文章来源:
http://lmgq.vip.sina.com/tech/jsadvancedlesson/c2p1.htm
发表时间:
2004-9-21 14:43:00
一、声明字符串:
var normal_monkey = "I&n ......
介绍两个关键的css
<style media="print">
.Noprint { DISPLAY: none }
.PageNext{ PAGE-BREAK-AFTER: always }
</style>第一个在不需要打印的标签上添加(子标签也将不被打印),第二个在需要换行的标签处添加(该标签所表示的内容将在当前打印的一页内)
接下来通过调用最基本的js语句
windo ......
1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
<table border oncontextmenu=return(false)> <td>no </table> 可用于Table
2. <body onselectstart="return false"> 取消选取、防止复制
3. onpaste="return false" 不准粘贴
4. oncopy ......