<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 下一頁 
    主站蜘蛛池模板: 99国产精品免费视频观看| 黄色a三级三级三级免费看| 国产成人免费视频| 亚洲日本一区二区三区在线| 成人免费观看男女羞羞视频| 免费女人18毛片a级毛片视频| 污污视频网站免费观看| 亚洲制服丝袜第一页| 色欲国产麻豆一精品一AV一免费| 亚洲午夜国产精品无码老牛影视| 三年片免费观看大全国语| 亚洲人成色77777| 国产va在线观看免费| 久久亚洲熟女cc98cm| 美女视频黄的全免费视频网站| 色天使亚洲综合在线观看| 在线免费视频一区二区| 美女免费精品高清毛片在线视| 亚洲高清最新av网站| 久久www免费人成精品香蕉| 亚洲v高清理论电影| 69堂人成无码免费视频果冻传媒| 亚洲人成色77777在线观看| 国产精品无码素人福利免费| 国产99久久久国产精免费| 亚洲AV无码专区国产乱码电影 | 最好2018中文免费视频| 日韩一卡2卡3卡4卡新区亚洲| 色欲A∨无码蜜臀AV免费播| 亚洲AV无码久久久久网站蜜桃| 日韩精品视频免费网址| rh男男车车的车车免费网站| 久久久久亚洲AV无码专区体验| 在线免费一区二区| 中国一级全黄的免费观看| 亚洲一级在线观看| 亚洲国产小视频精品久久久三级| 无码人妻一区二区三区免费看| 亚洲欧美日本韩国| 国产精品久久久亚洲| 破了亲妺妺的处免费视频国产|