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

    var myObject = {
      value :0,
      increment:function (inc){
        this.value += typeof inc ==='number' ? inc:1;
      }
    };
    myObject .increment();
    console.log(myObject.value);
    myObject .increment(2);
    console.log(myObject.value);
    
    var a=1;
    var b={
    a:2,
    c:function(){
    console.log(this.a);
    }
    }
    b.c();
    (b.c)();
    (0,b.c)();
    
    function f1(){
        var n=999;
        nAdd=function(){n+=1}
    console.log(n);
        function f2(){
          alert(n);
        }
        return f2;
      }
    var result=f1();
    result();
    nAdd();
    result();
    
    var name = "The Window";
      var object = {
        name : "My Object",
        getNameFunc : function(){
          return function(){
            return this.name;
          };
        }
      };
    alert(object.getNameFunc()());  
    
    
    var name = "The Window";
      var object = {
        name : "My Object",
        getNameFunc : function(){
          var that = this;
          return function(){
            return that.name;
          };
        }
      };
      alert(object.getNameFunc()());
  • 相关阅读:
    并查集
    归并排序
    树的操作
    活动安排
    动态规划-股票交易
    网络流
    linux 展开
    linux 反引号、单引号、双引号
    linux 命令行快捷键
    判断一个点是否在三角形内部和边界上
  • 原文地址:https://www.cnblogs.com/xiaotaiyang/p/5332601.html
Copyright © 2011-2022 走看看