Intercepts reads to the provided keys of target to run apply before returning
the value. This allows to initialize these properties lazily.
You should ensure that apply never throws.
Once one of the trapped properties was read, all the properties become normal properties.
Call lazyProperties on different subsets of keys to have independent lazy properties.
Calling lazyProperties multiple time on the same key is undefined behavior.
Type parameters
T
Parameters
target: T
The object holding the properties to intercept.
apply: function
The function called once one of the lazy properties is accessed. Its this value
will be target.
Intercepts reads to the provided
keys
oftarget
to runapply
before returning the value. This allows to initialize these properties lazily. You should ensure thatapply
never throws. Once one of the trapped properties was read, all the properties become normal properties. CalllazyProperties
on different subsets of keys to have independent lazy properties.Calling
lazyProperties
multiple time on the same key is undefined behavior.