I haven't seen this type of thing in any examples that I have come across. I need to create an attribute function that depends on other attributes. For example:
# coffeescript
class Person extends Backbone.Model
fullName: -> @get('first') + ' ' + @get('last')
class MyView extends Backbone.View
template: ...
render: ->
@$el.html @template(@model.toJSON())
new MyView(new Person(first:'Joe', last:'Moe)
# my template
<span><%= fullName %></span>
In most examples, I see that the model is always converted to JSON before passing to the template, so is there a way to set up the toJSON method to include this fullName
attribute? Or should I pass the model to the template instead?