trnc
trnc

Reputation: 21577

Backbone router + coffeescript not working?

+im playing arround with backbone and coffeescript, trying to get the router up and running. executing the following code, the init function works, but when browsing localhost/#world/3 nothing happens, although it should log something....

App =
  start: ->
    new App.TestRouter
    Backbone.history.start

App.TestRouter = Backbone.Router.extend
  routes: 
    "world/:id": "testView"

  initialize: ->
    new App.TestView
    console.log "Router init"

  testView: (id) ->
    console.log "testing! #{id}"

any advice here? am i blind?

Upvotes: 0

Views: 711

Answers (1)

Edward M Smith
Edward M Smith

Reputation: 10627

Backbone.history.start() is a function, so you need the () to execute it. Otherwise, you're just getting a reference to the function itself.

App =
  start: ->
    new App.TestRouter
    Backbone.history.start()

See this live jsFiddle:

http://jsfiddle.net/edwardmsmith/6pNLv/8/

Upvotes: 2

Related Questions