I'm still learning CoffeeScript and encountering some challenges with calling methods. Can someone help me out?
Here is the Card model I am working with:
class exports.Card extends Backbone.Model
defaults:
pip: '4'
suit: '♠'
color: 'b'
rows: ->
rows =
'4': [2, 0, 2]
rows[@pip]
Looking at a snippet from the template:
<ul class="col cols-<%= @card.rows()[0] %>">
When running this code, I'm getting an error message saying
Uncaught TypeError: Object #<Object> has no method 'rows'
I am uncertain if I am using the correct syntax for the rows method in the Card model, or if there is something else I am missing. Any insights would be appreciated. Thank you!
Update:
I've noticed that @card.property
always works, but @card.any_method()
does not. Currently, I am working around this by using properties, but I would like to understand why this behavior is happening. Thanks for your assistance!
Update 2:
In case it helps, I am using . Here's a snippet from the main.coffee
file showing 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()