内部和外部范围内具有相同名称的JavaScript访问本地变量

Chr*_*uts 13 javascript scope

给出以下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?
  }
}
Run Code Online (Sandbox Code Playgroud)

如何修改从内部函数范围内传递到外部函数作用域的id?

Jar*_*Par 13

不幸的是你不能.通过在嵌套函数中命名参数id,您已在外部函数中隐藏了参数.Javascript不包含用于访问阴影名称的工具.唯一的选择是为其中一个变量选择不同的名称.