zoukankan      html  css  js  c++  java
  • JS 闭包

    /***
     * JS 闭包
     **/
    //var result=[];
    //function foo(){
    //  var i= 0;
    //  for (;i<3;i=i+1){
    //      result[i]=function(){
    //          alert(i)
    //      }
    //  }
    //};
    //foo();
    //result[0](); // 3
    //result[1](); // 3
    //result[2](); // 3
    
    //var result=[];
    //function foo(){
    //  var i= 0;
    //  for (;i<3;i=i+1){
    //      result[i]=(function(j){
    //          return function(){
    //              alert(j);
    //          };
    //      })(i);
    //  }
    //};
    //foo();
    //result[0](); // 0
    //result[1](); // 1
    //result[2](); // 2
    
    var style = function(el, multiple) {
        this.resize = function(){
               //获取窗口宽度
            if (window.innerWidth)
                winWidth = window.innerWidth;
            else if ((document.body) && (document.body.clientWidth))
                winWidth = document.body.clientWidth;
            //获取窗口高度
            if (window.innerHeight)
                winHeight = window.innerHeight;
            else if ((document.body) && (document.body.clientHeight))
                winHeight = document.body.clientHeight;
            //通过深入Document内部对body进行检测,获取窗口大小
            if (document.documentElement && document.documentElement.clientHeight &&     document.documentElement.clientWidth)
            {
                winHeight = document.documentElement.clientHeight;
                winWidth = document.documentElement.clientWidth;
            }
            //结果输出至两个文本框
            el.style.width = winWidth + "px";
            el.style.height = winHeight + "px";
        }
    }
    
        var dom = function(){
            
        };
     
        dom.Show = function(){
            alert("Show Message");
        };
    
        dom.prototype.Display = function(){
            alert("Property Message");
        };
     
        //dom.Display(); //error
        dom.Show();  
        var d = new dom();
        d.Display();
        //d.Show(); //error
    
    //当浏览器窗口大小改变时
    window.onresize = function(){
        var main = document.getElementById("main");
        var init = new style(main, false);
        init.resize(main, false);
    }
  • 相关阅读:
    【转】大内高手—内存管理器
    [转]内存泄漏测试小工具 LeakDiag
    [转]内存泄漏测试小工具 LeakDiag
    (转)SplitContainer 控件(Windows 窗体)
    (转)c++内存分配优先使用内存池,而不是new,delete
    (转)C++内存池
    LeakDiag 使用注意
    Struts Validator验证器使用指南
    oracle JOB样例
    oralce杀session
  • 原文地址:https://www.cnblogs.com/rinack/p/5952763.html
Copyright © 2011-2022 走看看