Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo中代码错误 #24981

Closed
jekorx opened this issue Dec 9, 2024 · 0 comments · Fixed by #24994
Closed

demo中代码错误 #24981

jekorx opened this issue Dec 9, 2024 · 0 comments · Fixed by #24994
Labels
l10n-zh Issues related to Chinese content.

Comments

@jekorx
Copy link

jekorx commented Dec 9, 2024

MDN URL

https://developer.mozilla.org/zh-CN/docs/Web/API/AbortSignal

与此议题相关的小节或标题?

No response

哪些信息是错误、无用或不完善的?

```js
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
const res = await fetch(url, { signal: controller.signal });
const body = await res.json();
} catch (e) {
if (e.name === "AbortError") {
// Notify the user of abort.
// Note this will never be a timeout error!
} else {
// A network error, or some other problem.
console.log(`Type: ${e.name}, Message: ${e.message}`);
}
} finally {
clearTimeout(timeoutId);
}
```

finally 中无法读取到 try 代码块中的 timeoutId 变量

你期望看到什么?

let timeoutId;
try {
  const controller = new AbortController();
  timeoutId = setTimeout(() => controller.abort(), 5000);
  const res = await fetch(url, { signal: controller.signal });
  const body = await res.json();
} catch (e) {
  if (e.name === "AbortError") {
    // Notify the user of abort.
    // Note this will never be a timeout error!
  } else {
    // A network error, or some other problem.
    console.log(`Type: ${e.name}, Message: ${e.message}`);
  }
} finally {
  clearTimeout(timeoutId);
}

你有什么支持的链接、参考或引用?

No response

你还想补充什么内容?

No response

MDN metadata

Page report details
@jekorx jekorx added l10n-zh Issues related to Chinese content. needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Dec 9, 2024
@jasonren0403 jasonren0403 removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Dec 9, 2024
@jasonren0403 jasonren0403 linked a pull request Dec 10, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from To do - Issues to Archive/Closed in MDN translated-content l10n-zh Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
l10n-zh Issues related to Chinese content.
Projects
Status: Archive/Closed
Development

Successfully merging a pull request may close this issue.

2 participants