I'm new to CoffeeScript, and I seem to be having problems with the syntax for calling methods.
Here's the map model:
class exports.Card extends Backbone.Model defaults: pip: '4' suit: '♠' color: 'b' rows: -> rows = '4': [2, 0, 2] rows[@pip]
And the corresponding part of the template:
<ul class="col cols-<%= @card.rows()[0] %>">
which gives me an Uncaught TypeError: Object #<Object> has no method 'rows' error Uncaught TypeError: Object #<Object> has no method 'rows'
In particular, I am wondering if I am using the wrong syntax for the Card string method or if I just misunderstand something. Thanks in advance!
Update:
For some reason, @card.property always works fine, but @card.any_method() never works. I currently circumvented this using properties, but I would have liked it if someone could explain this behavior. Thanks again!
Update 2:
I use http://brunchwithcoffee.com if this helps anyone, and here is the main.coffee file to show how the @card instance is created and passed to the view.
window.app = {} app.routers = {} app.models = {} app.collections = {} app.views = {} Card = require('models/card_model').Card MainRouter = require('routers/main_router').MainRouter HomeView = require('views/home_view').HomeView CardView = require('views/card_view').CardView # app bootstrapping on document ready $(document).ready -> app.initialize = -> app.routers.main = new MainRouter() app.views.home = new HomeView() app.views.card = new CardView(model: new Card(color: 'r', suit: '♥', pip: '7')) app.routers.main.navigate 'home', true if Backbone.history.getFragment() is '' app.initialize() Backbone.history.start()
source share