Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.26 KB

README.md

File metadata and controls

38 lines (26 loc) · 1.26 KB

lade

npm version Build Status Code Climate Test Coverage devDependencies Status js-standard-style

Defines object properties evaluated and cached on the first read.

Usage

Define lazy property

var obj = {};

lade(obj, 'lazy', function() { return 40 + 2 });

obj.lazy;     // 42 (calls function, returns result as property value)
obj.lazy;     // 42 (uses cached property value from now on)

obj.lazy = 0; // overwrite property value
obj.lazy;     // 0

Define plain property

var obj = {};

lade(obj, 'prop', 'yes');

obj.prop;        // 'yes'

obj.prop = 'no'; // overwrite property value
obj.prop;        // 'no'