no-window
注意: 此规则是
recommended
规则集的一部分。在
deno.json
中启用完整规则集{ "lint": { "tags": ["recommended"] } }
使用 Deno CLI 启用完整规则集
deno lint --tags=recommended
禁止使用 window
对象。
window
全局对象在 Deno 中不再可用。Deno 没有 window,并且 typeof window === "undefined"
经常用于判断代码是否在浏览器中运行。
无效
const a = await window.fetch("https://deno.land");
const b = window.Deno.metrics();
console.log(window);
window.addEventListener("load", () => {
console.log("Loaded.");
});
有效
const a1 = await fetch("https://deno.land");
const a2 = await globalThis.fetch("https://deno.land");
const a3 = await self.fetch("https://deno.land");
const b1 = Deno.metrics();
const b2 = globalThis.Deno.metrics();
const b3 = self.Deno.metrics();
console.log(globalThis);
addEventListener("load", () => {
console.log("Loaded.");
});