如果有局部 window 变量,如何访问全局 window 变量?
How to access the global window variable if there's a local window variable?
出于好奇,您将如何访问具有此签名的函数内的全局 window 对象:
function bla(window){
// How to access the global 'window' object here? Because 'window' is now local.
}
你可以使用 globalThis
a = 1;
function x(window) {
console.log(window.a)
console.log(globalThis.a)
}
x({ a: 2 })
出于好奇,您将如何访问具有此签名的函数内的全局 window 对象:
function bla(window){
// How to access the global 'window' object here? Because 'window' is now local.
}
你可以使用 globalThis
a = 1;
function x(window) {
console.log(window.a)
console.log(globalThis.a)
}
x({ a: 2 })