var n=999;

  function f1(){
    alert(n);
  }

  f1(); // 999

  function f1(){
    var n=999;
  }

  alert(n); // error

  function f1(){
    n=999;
  }

  f1();

  alert(n); // 999

  function f1(){

    var n=999;

    function f2(){
      alert(n); // 999
    }

  }

  function f1(){

    var n=999;

    function f2(){
      alert(n);
    }

    return f2;

  }

  var result=f1();

  result(); // 999

  function f1(){

    var n=999;

    nAdd=function(){n+=1}

    function f2(){
      alert(n);
    }

    return f2;

  }

  var result=f1();

  result(); // 999

  nAdd();

  result(); // 1000

  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()());

发表回复