#13 Alias

Sponsor

Win a 1-year subscription to egghead.io (Worth $199)
Win a 1-year subscription to egghead.io (Worth $199)
Upgrade your programming skills.  Egghead.io delivers a constant stream of short, bite-sized instructional lessons on the latest web development technologies. These concise lessons are taught by industry veterans, with years of experience delivering software for clients.

Tip

This is such a simple “helper” but I love using it.  Specially when I am working with nested objects or don’t like the naming conventions of server-side model.  You can use computed.alias to alias another property.
Example 1:
Your model has a property called FirstName but you want to use firstName in your views and controller, you could add an alias:

You can get and set firstName the same way as model.FirstName.  It’s a nice shortcut.
Example 2:
If you have a nested model that has a profile object which has a gravatar object which has a Url property then accessing that property is PITA with this.get(‘model.profile.gravatar.url’) or in the view with {{model.profile.gravatar.url}}.  Instead add an alias to your controller:

And now you can simply, do this.get(‘gravatarUrl’) or {{gravatarUrl}}

That’s it for today!

Let me know what you think of today’s tip.  Thanks.

Published by

Emad Ibrahim

Author of asp .net MVC & TDD, entrepreneur, passionate technologist, programmer and productivity nut. more at http://t.co/oSJXPvzu