UNPKG

806 BMarkdownView Raw
1lazy-property
2=============
3Adds a lazily initialized property to an object.
4
5## Example
6
7```javascript
8var addLazyProperty = require("lazy-property")
9
10var obj = {}
11
12addLazyProperty(obj, "foo", function() {
13 console.log("initialized!")
14 return "bar"
15})
16
17//Access the property
18console.log(obj.foo)
19console.log(obj.foo)
20
21//Prints out:
22//
23// initialized!
24// bar
25// bar
26//
27```
28
29## Install
30
31 npm install lazy-property
32
33## API
34
35### `require("lazy-property")(obj, name, init[, enumerable])`
36Adds a lazily initialized property to the object.
37
38* `obj` is the object to add the property to
39* `name` is the name of the property
40* `init` is a function that computes the value of the property
41* `enumerable` if the property is enumerable (default `false`)
42
43## Credits
44(c) 2013 Mikola Lysenko. MIT License