Last active
January 2, 2016 14:29
-
-
Save alexspeller/8317125 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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 | |
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
Do you not need @get('firstName') in that last hack?
EDIT: Hmm. I guess not :P