超碰人人人人人,亚洲AV午夜福利精品一区二区,亚洲欧美综合区丁香五月1区,日韩欧美亚洲系列

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

js基礎:JavaScript的五個技巧

admin
2010年8月18日 10:21 本文熱度 4127
五條javascript技巧幫助你提高代碼質(zhì)量:
 1.只在<form>元素上使用submit事件
  綁定事件處理表單時,使用表單得submit事件而不是click事件。
 2.如果可點擊,確認是否是鏈接

 3.簡單的for循環(huán)優(yōu)化
  下面是對for循環(huán)做的一個非常簡單的改變,但是它確可以提高循環(huán)的效率

 

 

 for ( var i = 0; i < elements.length; ++i )
 for ( var i = 0, j = elements.length; i < j; ++i )


   第二行代碼中elements.length被存在變量j中,所以不必在每次循環(huán)的時候重復讀取它。

 
 4.事件處理時使用匿名函數(shù)(Use anonymous functions for event handlers)
  象下面這樣比較短的函數(shù)使用匿名函數(shù)比引用一個其他地方命名的函數(shù)可讀性要高

 

anchor.onclick = function() {
                    map.goToPosition( home );
                    return false;
                 }


 5.使用Array.join代替字符串連接(concatenating strings)

  遇到比較長的字符串連接的時使用Array.join代替字符串連接可以獲得更好的效率而且可讀性更高。
 

 

 var text = 'There are' + elements.length + 'members in the       

         elements array.';
                var text = ['There are', elements.length, 'members in the

elements array.'].join(' ');


 注:關于最后一條好像還有爭議

 

On 12 Sep 07

Stuart Colville said:

I'd disagree with the last item on using Array.join for concatenating strings: Firstly, the only real benefit in using this approach is when you are concatenating a lot of strings together. With three strings it may also actually be slower due to the overhead of initialising the array.

Secondly the performance increase from using Array.join in the right situation is generally only seen in IE due to it's slow JavaScript engine which has not seen the same levels of optimisations that have been made in other browsers.

 

 

Update

A number of people have mentioned to me that the Array.join technique for string concatenation is a bad one, particularly if you're only doing it with a small number of strings. Our benchmarks show it being faster for IE when you get to about 6/7 string concatenations, so it's been useful to us in some situations. But I'd agree with Stuart below that for the average situation it's not going to be worth it. However, I don't see using Array.join() for string concatenation as an abuse of JavaScript.

該文章在 2010/8/18 10:21:51 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務費用、相關報表等業(yè)務管理,結(jié)合碼頭的業(yè)務特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved