diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/finalizationregistry/unregister | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/finalizationregistry/unregister')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/finalizationregistry/unregister/index.html | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/finalizationregistry/unregister/index.html b/files/ja/web/javascript/reference/global_objects/finalizationregistry/unregister/index.html new file mode 100644 index 0000000000..3b2245b146 --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/finalizationregistry/unregister/index.html @@ -0,0 +1,134 @@ +--- +title: FinalizationRegistry.prototype.unregister() +slug: Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister +tags: + - FinalizationRegistry + - JavaScript + - Method + - Prototype + - Reference + - メソッド +translation_of: Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister +--- +<div>{{JSRef}}</div> + +<p><code>unregister</code> は対象のオブジェクトを {{jsxref("FinalizationRegistry")}} インスタンスから登録解除します。</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><code><var>registry</var>.unregister(<var>unregisterToken</var>);</code> +</pre> + +<h3 id="Parameters" name="Parameters">引数</h3> + +<dl> + <dt><code><var>unregisterToken</var></code></dt> + <dd>対象オブジェクトを登録したときに {{jsxref("FinalizationRegistry.prototype.register", "register")}} メソッドで使用したトークンです。</dd> +</dl> + +<h3 id="Return_value" name="Return_value">返値</h3> + +<p><code>undefined</code> です。</p> + +<h2 id="Notes" name="Notes">注</h2> + +<p>対象オブジェクトの回収が完了すると、レジストリに登録された状態ではなくなります。クリーンアップコールバックですべてに <code>unregister</code> を行う必要はありません。クリーンアップコールバックを受信しておらず、クリーンアップコールバックを受信する必要がなくなった場合にのみ <code>unregister</code> を呼び出してください。</p> + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_unregister" name="Using_unregister">unregister の使用</h3> + +<p>この例では、登録解除トークンとして同じオブジェクトを使用して対象のオブジェクトを登録し、その後、 <code>unregister</code> を介して対象のオブジェクトの登録を解除します。</p> + +<pre class="brush: js notranslate">class Thingy { + #cleanup = label => { + // ^^^^^−−−−− held value + console.error( + `The \`release\` method was never called for the object with the label "${label}"` + ); + }; + #registry = new FinalizationRegistry(this.#cleanup); + + /** + * Constructs a `Thingy` instance. Be sure to call `release` when you're done with it. + * + * @param label A label for the `Thingy`. + */ + constructor(label) { + // vvvvv−−−−− held value + this.#registry.register(this, label, this); + // target −−−−−^^^^ ^^^^−−−−− unregister token + } + + /** + * Releases resources held by this `Thingy` instance. + */ + release() { + this.#registry.unregister(this); + // ^^^^−−−−− unregister token + } +} +</pre> + +<p>この例では、登録解除トークンとして別のオブジェクトを使用して対象のオブジェクトを登録しています。</p> + +<pre class="brush: js notranslate"> { + // ^^^^−−−−− held value + console.error( + `The \`release\` method was never called for the \`Thingy\` for the file "${file.name}"` + ); + }; + #registry = new FinalizationRegistry(this.#cleanup); + + /** + * Constructs a `Thingy` instance for the given file. Be sure to call `release` when you're done with it. + * + * @param filename The name of the file. + */ + constructor(filename) { + this.#file = File.open(filename); + // vvvvv−−−−− held value + this.#registry.register(this, label, this.#file); + // target −−−−−^^^^ ^^^^^^^^^^−−−−− unregister token + } + + /** + * Releases resources held by this `Thingy` instance. + */ + release() { + if (this.#file) { + this.#registry.unregister(this.#file); + // ^^^^^^^^^^−−−−− unregister token + File.close(this.#file); + this.#file = null; + } + } +} +</pre> + +<h2 id="Specifications" name="Specifications">仕様書</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('WeakRefs', '#sec-finalization-registry.prototype.unregister', 'FinalizationRegistry.prototype.unregister')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> + +<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div> + +<p>{{Compat("javascript.builtins.FinalizationRegistry.unregister")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("FinalizationRegistry")}}</li> +</ul> |
