代码之家  ›  专栏  ›  技术社区  ›  Chris Shouts

javascript访问内部和外部作用域中同名的本地变量

  •  11
  • Chris Shouts  · 技术社区  · 14 年前

    给定以下javascript:

    var someFunction = function(id) {
      //do some stuff
      var modifyId = function(id) {
         //do some stuff
         outer.id = id; //is there any way to modify the id variable in the outer scope from here?
      }
    }
    

    如何修改从内部函数范围传递到外部函数范围的ID?

    4 回复  |  直到 14 年前
        1
  •  11
  •   JaredPar    14 年前

    id

        2
  •  2
  •   Pointy    14 年前

        3
  •  1
  •   Å ime Vidas Zim84    14 年前
    var someFunction = function(id) {
      //do some stuff
      var oid = id;
      var modifyId = function(id) {
         //do some stuff
         // you can access the outer id via the oid variable
      }
    }
    

        4
  •  1
  •   Adam Byrtek    14 年前