美文网首页
无标题文章

无标题文章

作者: BlackWingXu | 来源:发表于2017-12-05 16:50 被阅读0次
    function setupSomeGlobals() {
        // Local variable that ends up within closure
        var num = 666;
        // Store some references to functions as global variables
        gAlertNumber = function() { alert(num); }
        gIncreaseNumber = function() { num++; }
        gSetNumber = function(x) { num = x; }
    }
    /*setupSomeGlobals(); // 为三个全局变量赋值
    gAlertNumber(); //666
    gIncreaseNumber();
    gAlertNumber(); // 667
    gSetNumber(12);//
    gAlertNumber();//12*/
    
    function myClosure(X){
        var temp="Hello "+X;
        return  function () {
            console.log(temp)
        }
    }
    myClosure("closure")()
    var iNum=10;
    function add(num1,num2){
            function doAdd(){return num1+num2+iNum;}
            return doAdd();
    }
    var name = "The Window";
    var object = {
        name : "My Object",
        getNameFunc : function(){
            return function(){
                return this.name;
            };
        }
    };
    console.log(object.getNameFunc()());
    function  va() {
       var  name = "My Object";
    
        return    function getNameFunc() {
            return name;
        }
    }
    console.log(va()())
    var name = "The Window";
    var object = {
        name : "My Object",
        getNameFunc : function(){
            var that = this;
            return function(){
                return that.name;
            };
        }
    };
    console.log(object.getNameFunc()());
    

    相关文章

      网友评论

          本文标题:无标题文章

          本文链接:https://www.haomeiwen.com/subject/xumcixtx.html