Skip to content

Instantly share code, notes, and snippets.

@teramako
Forked from tetsuharuohzeki/es5-lazygetter.js
Created June 2, 2012 03:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teramako/2856412 to your computer and use it in GitHub Desktop.
Save teramako/2856412 to your computer and use it in GitHub Desktop.
ES5 lazy getter function
function lazyGetter(aObject, aName, aLambda) {
Object.defineProperty(aObject, aName, {
get: function () {
var val = aLambda.call(aObject);
Object.defineProperty(aObject, aName, { value: val, writable: true });
return val;
},
configurable: true,
enumerable : true,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment