Skip to content

Instantly share code, notes, and snippets.

@andreypopp
Created July 10, 2013 23:17
Show Gist options
  • Select an option

  • Save andreypopp/5971112 to your computer and use it in GitHub Desktop.

Select an option

Save andreypopp/5971112 to your computer and use it in GitHub Desktop.
lazyproperty = (obj, name, func, enumerable) ->
Object.defineProperty obj, name,
configurable: true
enumerable: not not enumerable
get: ->
value = func.call(this)
Object.defineProperty(this, name,
{value, enumerable: !!enumerable, writable: true})
value
set: (value) ->
Object.defineProperty(this, name,
{value, enumerable: !!enumerable, writable: true})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment