From 0a58ccb7fe68fc4f6171f1d3e6430739c7ff8802 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Thu, 10 Mar 2022 23:02:45 +0900 Subject: 2022/02/18 時点の英語版に同期 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/ja/web/api/cleartimeout/index.md | 134 ++++++++++++++------------------- 1 file changed, 55 insertions(+), 79 deletions(-) (limited to 'files/ja/web') diff --git a/files/ja/web/api/cleartimeout/index.md b/files/ja/web/api/cleartimeout/index.md index bc1b59314e..5397448076 100644 --- a/files/ja/web/api/cleartimeout/index.md +++ b/files/ja/web/api/cleartimeout/index.md @@ -1,101 +1,77 @@ --- -title: WindowOrWorkerGlobalScope.clearTimeout() +title: clearTimeout() slug: Web/API/clearTimeout tags: - API - HTML DOM - - Method - - Reference - - WindowOrWorkerGlobalScope - - clearTimeout - メソッド - リファレンス -translation_of: Web/API/WindowOrWorkerGlobalScope/clearTimeout + - clearTimeout +browser-compat: api.clearTimeout +translation_of: Web/API/clearTimeout original_slug: Web/API/WindowOrWorkerGlobalScope/clearTimeout --- -
{{APIRef("HTML DOM")}}
+{{APIRef("HTML DOM")}} -

clearTimeout() は {{domxref("WindowOrWorkerGlobalScope")}} ミックスインのメソッドで、以前の {{domxref("WindowOrWorkerGlobalScope.setTimeout", "setTimeout()")}} の呼び出しによって以前に確立されたタイムアウトを解除します。

+グローバルの **`clearTimeout()`** メソッドは、 {{domxref("setTimeout()")}} の呼び出しによって以前に確立されたタイムアウトを解除します。 -

構文

+## 構文 -
scope.clearTimeout(timeoutID)
-
+```js +clearTimeout(timeoutID) +``` -

引数

+### 引数 -
-
timeoutID
-
解除したいタイマの ID です。 ID は setTimeout() の返値によって取得できます。
-
+- `timeoutID` + - : 解除したいタイムアウトの識別子です。この ID は対応する `setTimeout()` から返されたものです。 -

注目すべきは、 {{domxref("WindowOrWorkerGlobalScope.setTimeout", "setTimeout()")}} および {{domxref("WindowOrWorkerGlobalScope.setInterval", "setInterval()")}} で使用される ID のプールは共有されますので、技術的には clearTimeout() および {{domxref("WindowOrWorkerGlobalScope.clearInterval", "clearInterval()")}} は互いに交換できます。しかし、明確化のため、そのようなことは避けてください。

+注目すべきは、 {{domxref("setTimeout()")}} および {{domxref("setInterval()")}} で使用される ID のプールは共有されますので、技術的には `clearTimeout()` および {{domxref("clearInterval()")}} は互いに交換できます。しかし、明確化のため、そのようなことは避けてください。 -

+## 例 -

ウェブページのコンテキストで以下のスクリプトを実行し、ページを一度クリックしてください。1秒後にメッセージがポップアップします。1秒間に複数回ページをクリックしても、アラートは一度しか表示されません。

+ウェブページのコンテキストで以下のスクリプトを実行し、ページを一度クリックしてください。1秒後にメッセージがポップアップします。1秒間に複数回ページをクリックしても、アラートは一度しか表示されません。 -
var alarm = {
-  remind: function(aMessage) {
-    alert(aMessage);
-    this.timeoutID = undefined;
-  },
+```js
+const alarm = {
+  remind: function(aMessage) {
+    alert(aMessage);
+    this.timeoutID = undefined;
+  },
 
-  setup: function() {
-    if (typeof this.timeoutID === 'number') {
-      this.cancel();
-    }
+  setup: function() {
+    if (typeof this.timeoutID === 'number') {
+      this.cancel();
+    }
 
-    this.timeoutID = window.setTimeout(function(msg) {
-      this.remind(msg);
-    }.bind(this), 1000, 'Wake up!');
-  },
+    this.timeoutID = setTimeout(function(msg) {
+      this.remind(msg);
+    }.bind(this), 1000, 'Wake up!');
+  },
 
-  cancel: function() {
-    window.clearTimeout(this.timeoutID);
-  }
+  cancel: function() {
+    clearTimeout(this.timeoutID);
+  }
 };
-window.onclick = function() { alarm.setup(); };
-
- -

メモ

- -

clearTimeout() へ妥当ではない ID を渡しても、何の効果もありません。例外は発生しません。

- -

仕様書

- - - - - - - - - - - - - - - - - - - - - -
仕様書状態備考
{{SpecName('HTML WHATWG', 'webappapis.html#dom-cleartimeout', 'WindowOrWorkerGlobalScope.clearTimeout()')}}{{Spec2("HTML WHATWG")}}最新の仕様で、メソッドを WindowOrWorkerGlobalScope ミックスインに移動。
{{SpecName('HTML WHATWG', 'webappapis.html#dom-cleartimeout', 'clearTimeout()')}}{{Spec2('HTML WHATWG')}}
- -

ブラウザーの互換性

- -

{{Compat("api.WindowOrWorkerGlobalScope.clearTimeout")}}

- -

関連情報

- - +window.addEventListener('click', () => alarm.setup() ); +``` + +## メモ + +`clearTimeout()` へ妥当ではない ID を渡しても、何の効果もありません。例外は発生しません。 + +## 仕様書 + +{{Specifications}} + +## ブラウザーの互換性 + +{{Compat}} + +## 関連情報 + +- {{domxref("setTimeout()")}} +- {{domxref("setInterval()")}} +- {{domxref("clearInterval()")}} +- {{domxref("Window.requestAnimationFrame()")}} +- [_Daemons_ 管理](/ja/docs/JavaScript/Timers/Daemons) -- cgit v1.2.3-54-g00ecf