Last active
December 11, 2015 19:48
-
-
Save shesek/4650898 to your computer and use it in GitHub Desktop.
getter, setter and lazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multi = (fn) -> (obj, name, a) -> | |
if a? then fn obj, name, a | |
else fn obj, name_, a_ for name_, a_ of name | |
def = (obj, name, prop) -> | |
prop.configurable ?= true | |
prop.enumerable ?= true | |
Object.defineProperty obj, name, prop | |
module.exports = exports = | |
etter: multi def | |
getter: multi (obj, name, get) -> def obj, name, { get } | |
setter: multi (obj, name, set) -> def obj, name, { set } | |
lazy: multi (obj, name, get) -> exports.getter obj, name, -> | |
value = get.call this | |
def this, name, { value, writable: false } | |
value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "etter", | |
"version": "0.1.1", | |
"main": "etter.coffee", | |
"repository": { | |
"type": "git", | |
"url": "git://gist.github.com/4650898.git" | |
}, | |
"license": "BSD" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment