Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Using model.attr() as a proxy for "helper" methods - good practise or confusing?

$
0
0
JMVC 3.2.4 here,

I've recently started using the model getters to represent attributes that are not provided on instantiation and are effectively helper methods. Here's an example:

Model
  1. getVerified: function() {
  2.       return someExpression ? true : false
  3. }
Template
  1. <% if (model.attr('verified')) { %>Verified Only Content<% } %>

There is the argument that this could be made more comprehensible by treating the method as a helper and to call the helper method in the template instead of using the attr() proxy.

My feeling is that "verified" can be effectively treated as a model attribute, regardless of it actually directly mapping to a data property being fed into the model instance. By doing this I can increase the use of attr() across the codebase and reinforce it's use (as it is not exclusively used everywhere).

What do you think?

Viewing all articles
Browse latest Browse all 3491

Trending Articles