https://github.com/apiko-dev/meteor-coffeescript-property
Create a property in CoffeeScript easy!
https://github.com/apiko-dev/meteor-coffeescript-property
Last synced: 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 (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-13T07:57:27.000Z (almost 11 years ago)
- Last Synced: 2025-03-05T17:53:30.538Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://jssolutionsdev.com/
- Size: 145 KB
- Stars: 4
- Watchers: 15
- 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 [](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
```