deref
method returns the
WeakRef
instance's target object, or
undefined
if the target object has been garbage-collected.
obj = ref.deref();
The target object of the WeakRef, or
undefined
if the object has been garbage-collected.
见
Notes on WeakRefs
section of the
WeakRef
page for some important notes.
见
范例
section of the
WeakRef
page for the complete example.
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;
}
};
| 规范 |
|---|
|
WeakRefs
The definition of 'WeakRef.prototype.deref()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
deref
|
Chrome 84 | Edge 84 | Firefox 79 | IE No | Opera No | Safari No | WebView Android 84 | Chrome Android 84 | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
nodejs
13.0.0
Disabled
|
完整支持
不支持
用户必须明确启用此特征。
WeakRef
WeakRef.prototype.deref()
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()