arrow17 Comments
  1. Tomasz Mazur
    May 10 - 1:01 pm


    render: =>
    $(@el).html(this.template(@model.toJSON()))
    this.setContent()
    return this

    can be simpler:


    render: =>
    $(@el).html(@template(@model.toJSON()))
    @setContent()
    @

    you don’t have to write “return” statement, because last expression is always returned in CoffeeScript (similiar to ruby)

    • Kamran Ayub
      Aug 12 - 1:00 pm

      I knew you could use the @ at the end and it would “return this” but personally I thought that might be a tiny bit confusing to people and it looks weird when you have a nested block before it

      classFunc: ->
          someVar = 1
          @collection.each ->
              # do some stuff
              processTask task
       
          @

      I prefer blank lines in-between statements (usually). Personal preference, it’s cool CoffeeScript doesn’t care.

  2. [...] the other stuff.How CoffeeScript makes jQuery more fun than ever.Using Backbone.js with CoffeeScript.SpaceX的航天传奇——商业公司击败举国体制的典范。 第一百八十天 [...]

  3. Jamie van Dyke
    May 23 - 10:14 am

    I’m not sure, but in that last example I think you can go even further with the ‘this.’ translations:

    Forked Gist

    • Jason Porritt
      Jun 09 - 9:13 am

      Yes, you are correct, Jamie. As Tomasz pointed out above, we could take the ‘this.’ translations further. Interestingly, I found it felt odd at first because I’m used to seeing @ associated only with variables, not function calls. However, I am slowly getting more comfortable with @ meaning ‘this.’ in non-variable contexts.

  4. Jason Miesionczek
    May 24 - 1:12 pm

    So what is your workflow for working with CoffeeScript + Backbone? What web framework do you use?

    • Jason Porritt
      Jun 09 - 9:20 am

      Jason, we are writing a mobile web application that communicates with a JSON API (a separate project). For the mobile web app itself we’re using Staticmatic2 to generate static assets from our Haml, Sass, and Coffeescript. The JSON API was written in .NET.

  5. [...] Using Backbone.js with CoffeeScript | Atomic Spin Så här snyggt blir det när du kör Backbone och CofeeScript tillsammans! [...]

  6. [...] Using Backbone.js with CoffeeScript | Atomic Spin – [...]

  7. GeorgeR
    Aug 21 - 10:40 pm

    It would be great if you could fix the missing snippets!

  8. GeorgeR
    Aug 21 - 10:41 pm

    Oh wait they just showed up. What.

  9. Mosselman
    Jan 03 - 6:17 am

    Hi, thank you for the great tips! There is one thing I got stuck on though, using the fat arrow instead of _.bindAll didn’t do the trick for me. I had some problems with ‘Cannot call ‘xyz’ of undefined when I refered to ‘this’ (or @). When I DID use _.bindAll there were no problems. It really is a shame, because in the past, before using coffeescript, I had some bugs as the result of forgetting to include or remove _.bindAll arguments.

    Despite this, the whole post is great as a quick reference to coffeescript snippets for backbone.js.

    Thanks!

  10. Ryan
    Apr 16 - 1:52 pm

    You can also condense $(@el) to @$el which is the view’s el pre-wrapped for you.

  11. Evgeny
    Apr 27 - 5:07 pm

    You can turn it to be a bit more idiomatic CoffeeScript,

    $(@el).html(this.template(@model.toJSON()))

    turns into this:

    ($ @el).html(@template @model.toJSON())
  12. [...] example uses CoffeeScript. You can see a little more about using Backbone.js and CoffeeScript in a previous [...]

  13. Jonah
    Oct 06 - 8:04 pm

    Hey just wanted to give you a quick heads up. The text in
    your content seem to be running off the screen in Firefox.
    I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I’d post to let you know.

    The design look great though! Hope you get the problem solved soon.
    Thanks

  14. Science
    Nov 22 - 8:19 am

    Hey there! I just wanted to ask if you ever have any trouble with hackers?

    My last blog (wordpress) was hacked and I ended
    up losing a few months of hard work due to no back up. Do you have any methods to protect against hackers?

Mobile Theme