<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 閱讀(1247) | 評論 (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 閱讀(261) | 評論 (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 閱讀(633) | 評論 (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 閱讀(633) | 評論 (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 閱讀(328) | 評論 (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 閱讀(409) | 評論 (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 閱讀(105) | 評論 (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 閱讀(269) | 評論 (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 閱讀(294) | 評論 (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 閱讀(184) | 評論 (0)編輯 收藏

    僅列出標題
    共4頁: 上一頁 1 2 3 4 下一頁 
    主站蜘蛛池模板: 亚洲视频精品在线| 亚洲欧洲无码AV电影在线观看| 亚洲午夜精品一区二区| 国产精品综合专区中文字幕免费播放| 国产又粗又猛又爽又黄的免费视频 | 免费一级全黄少妇性色生活片 | 人禽伦免费交视频播放| www国产亚洲精品久久久日本| 亚洲欧美在线x视频| 国产又大又粗又硬又长免费 | 国产成人无码免费看片软件| 亚洲欧洲久久av| 国产免费MV大全视频网站| 久久精品国产亚洲一区二区三区 | 日本zzzzwww大片免费| 国产成人精品日本亚洲11| 成人性生活免费视频| 久久精品国产亚洲av瑜伽| 免费一级毛片在线播放不收费| 日日躁狠狠躁狠狠爱免费视频| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 日本亚洲免费无线码| 日本不卡高清中文字幕免费| 免费无遮挡无码视频在线观看| 国产亚洲精品自在线观看| 永久免费A∨片在线观看| 亚洲欧洲精品在线| 全免费a级毛片免费看不卡| 免费看一级高潮毛片| 亚洲AV日韩AV永久无码下载| 2021国产精品成人免费视频| 亚洲av无码成人影院一区 | 免费一级做a爰片性色毛片| 一个人看的www免费高清| 亚洲国产精品一区二区第一页| 国产电影午夜成年免费视频| AV激情亚洲男人的天堂国语| 国产V亚洲V天堂A无码| 成人免费看片又大又黄| 久久久WWW成人免费精品| 国产日本亚洲一区二区三区|