register()
method registers an object with a
FinalizationRegistry
instance so that if the object is garbage-collected, the registry's callback may get called.
registry.register(target, heldValue, [unregisterToken]);
target
The target object to register.
heldValue
target
对象。
unregisterToken
可选
unregister
method later to unregister the target object. If provided (and not
undefined
), this must be an object. If not provided, the target cannot be unregistered.
undefined
.
见
Avoid where possible
and
Notes on cleanup callbacks
sections of the
FinalizationRegistry
page for important caveats.
The following registers the target object referenced by
target
, passing in the held value
"some value"
and passing the target object itself as the unregistration token:
registry.register(target, "some value", target);
The following registers the target object referenced by
target
, passing in another object as the held value, and not passing in any unregistration token (which means
target
can't be unregistered):
registry.register(target, {"useful": "info about target"});
| 规范 |
|---|
|
WeakRefs
The definition of 'FinalizationRegistry.prototype.register' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
register
|
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
|
完整支持
不支持
用户必须明确启用此特征。
FinalizationRegistry
FinalizationRegistry.prototype.register()
FinalizationRegistry.prototype.unregister()
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()