aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.html69
1 files changed, 69 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.html b/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.html
new file mode 100644
index 0000000000..9d9fdbdba1
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/weakref/deref/index.html
@@ -0,0 +1,69 @@
+---
+title: WeakRef.prototype.deref()
+slug: Web/JavaScript/Reference/Global_Objects/WeakRef/deref
+translation_of: Web/JavaScript/Reference/Global_Objects/WeakRef/deref
+---
+<div>{{JSRef}}</div>
+
+<div></div>
+
+<div><code>deref</code>方法返回{{jsxref("WeakRef")}} 实例的目标对象,如果目标对象已被垃圾收集,则返回<code>undefined</code> 。</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate"><code><var>obj</var> = <var>ref</var>.deref();</code>
+</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<p>返回WeakRef的目标对象,如果该对象已被垃圾收集,则返回<code>undefined</code> 。</p>
+
+<h2 id="说明">说明</h2>
+
+<p>有关一些重要说明,请参阅{{jsxref("WeakRef")}}页面上的<a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef#Notes_on_WeakRefs">Notes on WeakRefs</a> 。</p>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="使用deref">使用deref</h3>
+
+<p>有关<a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef#Examples">完整示例</a>,请参阅{{jsxref("WeakRef")}}页面的示例部分。</p>
+
+<pre class="brush: js notranslate">const tick = () =&gt; {
+ // Get the element from the weak reference, if it still exists
+ const element = this.ref.deref();
+ if (element) {
+ element.textContent = ++this.count;
+ } else {
+ // The element doesn't exist anymore
+ console.log("The element is gone.");
+ this.stop();
+ this.ref = null;
+ }
+};</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">规范</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('WeakRefs', '#sec-weak-ref.prototype.deref', 'WeakRef.prototype.deref()')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("javascript.builtins.WeakRef.deref")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{jsxref("WeakRef")}}</li>
+</ul>