Class: WeakRef

WeakRef

A simple reference wrapper that emulates a weak reference. We seem to have no other option, since WeakMap and WeakSet are not enumerable (so what is the point of WeakMap and WeakSet if you still need to manage the keys?!) and there is no native way to create a weak reference.


new WeakRef(target, ttl)

Initializes the weak reference to the target reference.

Parameters:
Name Type Description
target Object

The target reference that should be referenced by this weak reference.

ttl number

The maximum number of milliseconds the weak reference should be kept. The reference will be discarded once ACCESSED after the specified timeout.

Members


_expiration :number

The UNIX timestamp with millisecond precision marking the moment at or after which the reference will be discarded.

Type:
  • number

<nullable> _reference :Object

The actual target reference, or null if the reference has been already discarded.

Type:
  • Object

target

Returns the target reference, provided that the target reference is still alive. Returns null if the reference has been discarded.