Reputation: 2076
$ ->
window.app.helpers = new class Helpers
constructor: (@name) ->
@slideRecipeId = $("#slideRecipe")
@specialities = ["A", "B", "C"]
setTimeout @countUpRecipes, 3000
countUpRecipes: ->
@slideRecipeId.html(@specialities[Math.floor(Math.random() * @specialities.length)])
The problem is that on load I get these errors:
Uncaught TypeError: Cannot read property 'length' of undefined
What's wrong with the code ? Thanks.
Upvotes: 0
Views: 860
Reputation: 10349
You need to bind the context when calling @countUpRecipes
:
setTimeout =>
@countUpRecipes
, 3000
Upvotes: 1