Skip to content

Instantly share code, notes, and snippets.

@alexspeller
Last active January 2, 2016 14:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexspeller/8317125 to your computer and use it in GitHub Desktop.
Save alexspeller/8317125 to your computer and use it in GitHub Desktop.
# Ember defines function() {}.property() as a shortcut
# for making computed properties
name: (->
@get('firstName') + " " + @get('lastName')
).property('firstName', 'lastName')
# It is a shortcut to wrapping the function inside
# Em.computed. However, using the "long way" is
# actually a bit nicer in coffeescript due to not
# requiring the parentheses
name: Em.computed 'firstName', 'lastName', ->
@get('firstName') + " " + @get('lastName')
# or, you can assign a global helper to reduce
# character count even further
window.prop = Em.computed
name: prop 'firstName', 'lastName', ->
@get('firstName') + " " + @get('lastName')
# or, use eval hax ;-D http://emberjs.jsbin.com/aCuKuqu/26/edit
# this way you don't even need to use @get()!
# (Note: the others are built in, this is a dodgy hack)
fullName: prop "firstName lastName", ->
firstName + " " + lastName
@ZackMattor
Copy link

Do you not need @get('firstName') in that last hack?

EDIT: Hmm. I guess not :P

@alexspeller
Copy link
Author

Nope, that's why it's an eval hack ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment