Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lazy properties for ES5
function lazyProperty(object, name, create) {
Object.defineProperty(object, name, {
configurable: true, // or false if defined on prototype objects
enumerable: false,
get: function() {
return this[name] = create(this);
},
set: function(value) {
Object.defineProperty(this, name, {
configurable: true,
enumerable: false,
value: value,
writable: true
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.