Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apiko-dev/meteor-coffeescript-property
Create a property in CoffeeScript easy!
https://github.com/apiko-dev/meteor-coffeescript-property
Last synced: about 2 months ago
JSON representation
Create a property in CoffeeScript easy!
- Host: GitHub
- URL: https://github.com/apiko-dev/meteor-coffeescript-property
- Owner: apiko-dev
- License: mit
- Created: 2015-06-26T09:01:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-08-13T07:57:27.000Z (over 9 years ago)
- Last Synced: 2023-02-27T07:07:48.339Z (almost 2 years ago)
- Language: JavaScript
- Homepage: http://jssolutionsdev.com/
- Size: 145 KB
- Stars: 4
- Watchers: 14
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# meteor-coffeescript-property
Nice approach for defining properties with getters and setters in CoffeeScript.
Made by [![Professional Meteor Development Studio](http://s30.postimg.org/jfno1g71p/jss_xs.png)](http://jssolutionsdev.com) - [Professional Meteor Development Company](http://jssolutionsdev.com)
You can use `property` function with nested getter and/or setter. Or just use `setter` and `getter` directly. In both cases you should pass property name as the first argument.
```coffeescript
class Woman
constructor: (name, age) ->
@name = name
@age = age
_age = null
@property 'age',
get: () ->
if 16 <= _age < 20 or 30 <= _age then _.random 20, 24 else _age
set: (newAge) ->
_age = newAge
@setter 'name', (newName) ->
@_name = newName
@getter 'name', () ->
"Hey! My name is #{@_name}. I'm #{@age} y.o. And bla-bla-bla..."
cristy = new Woman 'Cristy', 22
cristy.name
# Returns "Hey! My name is Cristy. I'm 22 y.o. And bla-bla-bla..."
cristy.age
# Return 22
```