在基于浏览器的环境中,如果它与模块内的函数参数具有相同的名称,该如何在模块级作用域内引用变量?
例如如果我有以下情况:
模块化Foo
let thisFoo = undefined;
export function do(foo) {
thisFoo = foo;
}
我可以将函数参数foo
的值分配给模块范围的变量thisFoo
,因为它们的命名不同。
但是,如果我也用与功能参数相同的名称来命名模块级变量,那我将如何引用模块级变量呢?
模块化Foo
let foo = undefined;
export function do(foo) {
// I'd like to refer to the module level variable foo
// for the LHS, and assign to it the function level
// variable foo
// ???
// obviously, doesn't make any sense
foo = foo;
// this would still refer to the window object, right?
this.foo = foo;
}