<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    七段

    無論怎樣,請讓我先感謝一下國家。

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      35 Posts :: 2 Stories :: 7 Comments :: 0 Trackbacks
    Efficient JavaScript coding
    1, 盡可能選擇高效的method
    e.g.
    如果沒有必要,可以不用regular expression
    String.indexOf, String.lastIndexOf > String.match, String.search, String.replace

    2, 面對large loop就要斤斤計較
    2.1 Create once, use repeatedly
    for( var i = 0, oNode; oNode = oElement.childNodes[i]; i++ ) {
    if( oNode.nodeValue.match(/^\s*extra.*free/g) ) {
    //this creates the expression
    //it will be cached and re-used next time through the loop
    }
    }
    for( var i = 0, oNode; oNode = oElement.childNodes[i]; i++ ) {
    if( oNode.nodeValue.match(new RegExp(“^\s*extra.*free”,”g”)) ) {
    //this will always create a new copy of the expression,
    //and is generally much slower than creating static expressions.
    }
    }

    2.2 Referencing element once, use repeatedly
    var _table =$("#tableId")
    for (var index in json) {
    otherFun(_table, json[index]);
    };


    3 eval is evil
    Eval 或者 new Function() 執行時,瀏覽器先創建整個scripting環境(就像一個新頁面),導入scope chain中所有變量,執行script,gc, 最后導出所有變量到當前環境。(in a word, cost much)另外,js engine還不能對它們進行cache優化。

    4 less is more
    Less code, short naming
    Only add event listener what you need

    5 do less
    Take a short circuit
    e.g
    var logger=window.console && window.console.dir
    var logger=window.console || {}

    less XHR calling
    e.g. enable cache for the same request

    6 Reduce reflow
    每當添加element到document里,browser就會reflow整個頁面去計算如何重新定位和渲染。

    7,cache
    Enable cache for duplicated XHR calling
    Enable cache for js script file, so move out jscript from jsp to js file.

    Reference:
    http://slowjavascript.com/JavaScript_Performance_Rocks_Checklist.pdf


    已有 0 人發表留言,猛擊->>這里<<-參與討論


    JavaEye推薦




    文章來源:http://sevenduan.javaeye.com/blog/505272
    posted on 2009-10-31 14:49 sevenduan 閱讀(178) 評論(0)  編輯  收藏 所屬分類: JavaScript
    主站蜘蛛池模板: 四虎影视免费在线| 毛片免费在线播放| 一级毛片a女人刺激视频免费| 国产成人不卡亚洲精品91| 性感美女视频在线观看免费精品| 亚洲AV无码乱码精品国产| 亚洲精品无码不卡在线播HE | 亚洲区精品久久一区二区三区| 国产精品亚洲专区无码WEB| 免费无码精品黄AV电影| 亚洲色欲啪啪久久WWW综合网| 免费无码黄网站在线看| 99re热免费精品视频观看| 日韩视频在线精品视频免费观看| 亚洲AV无码一区二区三区在线观看| 99亚洲精品高清一二区| 日亚毛片免费乱码不卡一区 | 日韩免费无码视频一区二区三区| 免费国产成人午夜私人影视| 亚洲av片在线观看| 亚洲欧洲精品成人久久奇米网 | 亚洲精品午夜在线观看| 欧美日韩国产免费一区二区三区 | 国产免费黄色大片| a毛片成人免费全部播放| 免费看www视频| 又硬又粗又长又爽免费看| 久久精品国产精品亚洲艾 | 国产亚洲精品免费视频播放| 无码av免费一区二区三区| 亚洲AV色吊丝无码| 又粗又硬又黄又爽的免费视频| 亚洲日韩亚洲另类激情文学| 亚洲国产成人精品无码久久久久久综合 | 日韩伦理片电影在线免费观看| 亚洲AV无码专区在线亚| 日韩免费一级毛片| 日韩免费在线视频| 亚洲色四在线视频观看| 国产综合免费精品久久久| 亚洲最大黄色网址|