A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref below:

WeakRef.prototype.deref() - JavaScript | MDN

WeakRef.prototype.deref()

Baseline Widely available

deref方法返回WeakRef 实例的目标对象,如果目标对象已被垃圾收集,则返回undefined 。

语法 返回值

返回 WeakRef 的目标对象,如果该对象已被垃圾收集,则返回undefined 。

说明

有关一些重要说明,请参阅WeakRef页面上的Notes on WeakRefs 。

示例 使用 deref

有关完整示例,请参阅WeakRef页面的示例部分。

const tick = () => {
  // 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;
  }
};
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4