Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod Call Syntax in CoffeeScript
    primarykey
    data
    text
    <p>I'm new to CoffeeScript, and I seem to be having trouble with the syntax for calling methods.</p> <p>Here's the Card model:</p> <pre><code>class exports.Card extends Backbone.Model defaults: pip: '4' suit: '♠' color: 'b' rows: -&gt; rows = '4': [2, 0, 2] rows[@pip] </code></pre> <p>And the relevant portion of the template:</p> <pre><code>&lt;ul class="col cols-&lt;%= @card.rows()[0] %&gt;"&gt; </code></pre> <p>which is giving me the error <code>Uncaught TypeError: Object #&lt;Object&gt; has no method 'rows'</code></p> <p>Specifically, I'm wondering if I'm using incorrect syntax for the rows method of Card or if I'm just misunderstanding something. Thanks in advance!</p> <p><strong>Update:</strong></p> <p>For some reason, <code>@card.property</code> always works fine, but <code>@card.any_method()</code> never does. I've gotten around this at the moment by using properties, but I'd love it if someone was able to explain this behavior. Thanks again!</p> <p><strong>Update 2:</strong></p> <p>I'm using <a href="http://brunchwithcoffee.com" rel="nofollow">http://brunchwithcoffee.com</a> if it's a help to anyone, and here's the <code>main.coffee</code> file to show how the <code>@card</code> instance is being created and passed to the view.</p> <pre><code>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 -&gt; app.initialize = -&gt; 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() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload