1.1.4 • Published 3 months ago

@squeep/lazy-property v1.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago

@squeep/lazy-property

Defer property initialization until first access.

API

lazy(obj, name, initializer, descriptor, objectBound = true)

Add name property to obj, which will invoke initializer on first access and update name with the resulting value.
Property settings can be specified with descriptor, as in Object.defineProperty().
If objectBound is true and the lazy property is set on a prototype object, the property will be updated on the prototype object. If objectBound is false and on a prototype object, the property will be updated on the inherited object and the initializer will be invoked once for each inherited object accessed. The this object in initializer will be explicitly obj when objectBound is set, otherwise it will be this.
Returns obj.

Example

const { lazy } = require('@squeep/lazy-property');

const obj = {};
lazy(obj, 'prop', () => doSomethingExpensive());
const getItNow = obj.prop;
1.1.4

3 months ago

1.1.3

1 year ago

1.1.2

3 years ago

1.1.1

3 years ago