Thursday, 19 September 2013

With handlebars.js, is it ok to call nested object properties that my be undefined?

With handlebars.js, is it ok to call nested object properties that my be
undefined?

I noticed that defining the following in my Handlebars.js templates works
fine:
<input name="username" value="{{user.name}}">
This works even when:
user is undefined; and/or
user.name is undefined
However, I'm questioning how appropriate it is to do this. What's going on
in the background? Wouldn't the following be more appropriate, albeit
adding more cluttering?
<input name="username" value="{{#if user}}{{#if
user.name}}{{user.name}}{{/if}}{{/if}}">
Thanks.

No comments:

Post a Comment