Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/lazy-property
Lazy initialization for object properties
https://github.com/mikolalysenko/lazy-property
Last synced: about 2 months ago
JSON representation
Lazy initialization for object properties
- Host: GitHub
- URL: https://github.com/mikolalysenko/lazy-property
- Owner: mikolalysenko
- License: mit
- Created: 2013-07-08T16:28:22.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-10-19T07:40:52.000Z (about 9 years ago)
- Last Synced: 2024-10-10T21:41:03.916Z (3 months ago)
- Language: JavaScript
- Size: 189 KB
- Stars: 15
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
lazy-property
=============
Adds a lazily initialized property to an object.## Example
```javascript
var addLazyProperty = require("lazy-property")var obj = {}
addLazyProperty(obj, "foo", function() {
console.log("initialized!")
return "bar"
})//Access the property
console.log(obj.foo)
console.log(obj.foo)//Prints out:
//
// initialized!
// bar
// bar
//
```## Install
npm install lazy-property
## API
### `require("lazy-property")(obj, name, init[, enumerable])`
Adds a lazily initialized property to the object.* `obj` is the object to add the property to
* `name` is the name of the property
* `init` is a function that computes the value of the property
* `enumerable` if the property is enumerable (default `false`)## Credits
(c) 2013 Mikola Lysenko. MIT License