<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

    #

    他們有什么區別?我得意的笑 囧……
    1, null vs undefined
    2, new Object vs new Object()
    3, function foo(){} vs var foo=function foo(){}
    4,var a=b=undefined; vs var a,b;
    5,
    1 function Foo(){
    2 return true;
    3 }
    VS
    function Foo(){
    return 
              
    true;
    }
    6, var a =[[1,2,3],[1,2,3],[1,2,3]]
    a[1][2] VS a[1,2]

    posted @ 2009-12-13 22:16 sevenduan 閱讀(1242) | 評論 (1)編輯 收藏

    refer to : http://mir.aculo.us/2009/11/08/6-easy-things-you-can-do-to-improve-your-javascript-runtime-performance/

    #1 avoid function calls
    #2 embrace the language: []>array, {} > object
    #3 loop: no loop > loop
    #4 cache globals: function(){var w =window;}
    #5 expression tuning: false move to before &&, true move to before ||
    #6 what not to use: e.g. with , eval, try catch,

    posted @ 2009-12-13 16:54 sevenduan 閱讀(255) | 評論 (0)編輯 收藏

    1    c();
    2             //a();//runtime error: a is not a function
    3             //b();//runtime error: b is not defined
    4             function c(){};//c will be defined and assigned value when pre-compile
    5             var a = function b(){ //b will be delete, a will be defined when pre-compile, a assigned value when runtime
    6             };
    7             a();
    posted @ 2009-12-11 16:44 sevenduan 閱讀(626) | 評論 (0)編輯 收藏

     1 function buildFunction(productList, productWeight){
     2                 var totalweight = eval(productWeight.join("+"))
     3                 var weighedProducts = new Array()
     4                 var currentProducts = 0
     5                 while (currentProducts < productList.length) {
     6                     for (i = 0; i < productWeight[currentProducts]; i++) {
     7                         weighedProducts.push(productList[currentProducts]);
     8                     }
     9                     currentProducts++
    10                 }
    11                 return function(){
    12                     var randomnumber = Math.floor(Math.random() * totalweight)
    13                     return (weighedProducts[randomnumber]);
    14                 };
    15             };
    16             var productList = ["AK-47""Blade""Food""ByondGod"]
    17             var productWeight = [2002041];
    18             var myFun = buildFunction(productList, productWeight);
    19             for (var i = 0; i < 100; i++
    20                 document.writeln((i+1)+":"+myFun())
    posted @ 2009-12-11 13:56 sevenduan 閱讀(625) | 評論 (0)編輯 收藏

      (function(){
                    
    var uuid = 0;
                    
    var NEW = 0, PENDING = 1, FINISH = 2;
                    
    var RemoteRule = window.RemoteRule = function(fn, options){
                        
    this.id = uuid++;
                        
    this.fn = fn;
                        
    this.para = options.requestPara;
                        
    this.showTips = function(){
                            options.showTips();
                        }
                    }
                    
                    
    var RemoteValidator = window.RemoteValidator = function(){
                        
    this.rules = {};
                        
    this.status = {};
                    }
                    RemoteValidator.prototype 
    = {
                        addRule: 
    function(rule){
                            
    this.rules[rule.id] = rule;
                            
    this.status[rule.id] = NEW;
                        },
                        reset: 
    function(){
                            
    this.rules = {};
                            
    this.status = {};
                        },
                        validate: 
    function(callBack){
                            
    var self = this;
                            
    for (var id in self.rules) {
                                
    var rule = self.rules[id];
                                
    var updateFn = (function(){
                                    
    return function(data){
                                        
    if (data) {
                                            
    delete self.status[rule.id];
                                        }
                                        
    else {
                                            self.hasError 
    = true;
                                        }
                                        
    if (self.hasError) {
                                            rule.showTips();
                                        }
                                        
    var isEmpty = true;
                                        
    for (var id in self.status) {
                                            isEmpty 
    = false;
                                            
    break;
                                        }
                                        
    if (isEmpty) {
                                            callBack();
                                        }
                                    }
                                })();
                                self.status[rule.id] 
    = PENDING;
                                rule.fn(rule.para, updateFn);
                                
                            }
                        }
                    }
                    
                })();
                
                
    var dwrFnMock = function(para, callBack){
                    setTimeout(
    function(){
                        
    if (para.value > 0
                            callBack(
    true);
                        
    else 
                            callBack(
    false);
                    }, 
    1000);
                };
                
    var validator1 = new RemoteValidator();
                validator1.addRule(
    new RemoteRule(dwrFnMock, {
                    requestPara: {
                        value: 
    1
                    },
                    showTips: 
    function(){
                        alert(
    "hasError!");
                    }
                }));
                validator1.validate(
    function(){
                    alert(
    "submit");
                });
                
    var validator2 = new RemoteValidator();
                validator2.addRule(
    new RemoteRule(dwrFnMock, {
                    requestPara: {
                        value: 
    -1
                    },
                    showTips: 
    function(){
                        alert(
    "hasError!");
                    }
                }));
                validator2.validate(
    function(){
                    alert(
    "submit");
                })
    posted @ 2009-12-08 11:28 sevenduan 閱讀(323) | 評論 (0)編輯 收藏

    jQuery Common Coding tips:
    1, less code by chain coding
    2, Use data method instead of storing data inside the DOM.
        
     $('selector').data('meaningfullname', 'this is the data I am storing');
    // then later getting the data with
    $('selector').data('meaningfullname');

    3, If you are Manipulating the DOM a lot, use livequery.(1.3)
     
        $('div.edit').livequery('click', function(){
    //go into edit mode
    });

    4, Use classes as flags:With jQuery you can add a class with the addClass method and then check later if an element has the class with the hasClass method.
    5, use same function name to handle different arguments
    6, pass options for configuration data
    7, test your code by screw.unit
    8, make most jQuery code into resuable plugins

    jQuery plugin pattern tips:
    (from: http://www.learningjquery.com/2007/10/a-plugin-development-pattern)
       1.  Claim only a single name in the jQuery namespace
       2. Accept an options argument to control plugin behavior
       3. Provide public access to default plugin settings
       4. Provide public access to secondary functions (as applicable)
       5. Keep private functions private
       6. Support the Metadata Plugin

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


    JavaEye推薦




    文章來源:http://sevenduan.javaeye.com/blog/507354
    posted @ 2009-10-31 14:49 sevenduan 閱讀(402) | 評論 (0)編輯 收藏

    Should we do RegEx or not?
    *pros:
    save time and less efforts
    less code
    *cons:
    sometimes heavyweight or involves heavy processing
    complicated RegEx hidden bugs, hard to read/write

    In a word, we need to balance the pros and cons above before make a descision.
    How to parse RegEx?
    //TODO:


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


    JavaEye推薦




    文章來源:http://sevenduan.javaeye.com/blog/507054
    posted @ 2009-10-31 14:49 sevenduan 閱讀(103) | 評論 (0)編輯 收藏

    請給Array本地對象增加一個原型方法,它的用途是刪除數組條目中重復的條目(可能有多個),返回值是一個僅包含被刪除的重復條目的新數組。
        var hashCode = function(element){
    return element.sort().toSource();
    }
    Array.prototype.dell = function(hashCode){
    var deleList = [];
    var obj = {};
    do {
    var ele = this.pop();
    var key = hashCode(ele);
    if (obj[key]) {
    deleList.push(ele);
    }
    else {
    obj[key] = ele;
    }
    }
    while (this.length > 0);
    for (var key in obj) {
    this.push(obj[key]);
    }
    return deleList;
    }
    var list = [[3, 1], [1, 2], [1, 3]]
    expect([[1, 3]]).to(equal, list.dell(hashCode));
    expect([[1, 2], [1, 3]].sort()).to(equal, list.sort());


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


    JavaEye推薦




    文章來源:http://sevenduan.javaeye.com/blog/506830
    posted @ 2009-10-31 14:49 sevenduan 閱讀(264) | 評論 (0)編輯 收藏

    做為一個java coder,除了eclipse, firefox,也是Outlook的重度使用者。
    熟用以下快捷鍵是request code review, reply code review的制勝法寶。

    創建郵件。  Ctrl+Shift+M
    創建便箋。  Ctrl+Shift+N
    新建MO文檔。  Ctrl+Shift+H
    檢查姓名。  Ctrl+K
    面板切換。  F6
    答復郵件。  Ctrl+R
    移動項目。  Ctrl+Shift+V
    reply all。 Ctrl+Shift+R
    轉發郵件。 Ctrl+F
    “flag”。  Insert
    發送。          Alt+S

    拼寫檢查。  F7
    查找或替換。  F4
    增大縮進。  Ctrl+T
    減小縮進。 Ctrl+Shift+T
    下劃線。 Ctrl+U
    增大字號。 Ctrl+]
    減小字號。 Ctrl+[或Ctrl+Shift+<
    清除格式。  Ctrl+空格鍵
    文本左對齊。  Ctrl+L
    文本居中對齊。 Ctrl+E
    文本右對齊。 Ctrl+R

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


    JavaEye推薦




    文章來源:http://sevenduan.javaeye.com/blog/506109
    posted @ 2009-10-31 14:49 sevenduan 閱讀(290) | 評論 (0)編輯 收藏

    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 @ 2009-10-31 14:49 sevenduan 閱讀(178) | 評論 (0)編輯 收藏

    僅列出標題
    共4頁: 上一頁 1 2 3 4 下一頁 
    主站蜘蛛池模板: 在线v片免费观看视频| 国产精品综合专区中文字幕免费播放| 国产成人无码区免费内射一片色欲 | 国产在线观看片a免费观看| 亚洲美女视频一区| 国产成人精品免费视频动漫| 亚洲美女在线观看播放| 国产福利在线观看免费第一福利| 亚洲日本香蕉视频| 女人与禽交视频免费看| 另类专区另类专区亚洲| 亚洲中文字幕视频国产| AAA日本高清在线播放免费观看| 无码久久精品国产亚洲Av影片| 最近中文字幕无免费| 亚洲粉嫩美白在线| 亚洲成a人片在线播放| 日韩在线一区二区三区免费视频| 精品亚洲成α人无码成α在线观看| 免费a级毛片无码a∨免费软件| 久久亚洲中文字幕精品有坂深雪| 男女做羞羞的事视频免费观看无遮挡| 亚洲香蕉久久一区二区| 免费一看一级毛片人| 久久久久久久久久免免费精品| 亚洲福利一区二区精品秒拍| 精品国产麻豆免费网站| 中文字幕永久免费| 亚洲天堂中文字幕在线观看| 国产成人免费片在线观看| 国内精品免费久久影院| 亚洲一级毛片在线播放| 亚洲Aⅴ无码一区二区二三区软件 亚洲AⅤ视频一区二区三区 | 亚洲日韩人妻第一页| 一级成人a毛片免费播放| 国产成人精品日本亚洲网址| 亚洲人成国产精品无码| 免费大片黄在线观看yw| ssswww日本免费网站片| 亚洲伊人久久精品| 久久久久久亚洲精品不卡|