Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:53:14+00:00 2026-05-28T19:53:14+00:00

Rails app, learning CoffeeScript and Backbone.js: Uncaught TypeError: Cannot use ‘in’ operator to search

  • 0

Rails app, learning CoffeeScript and Backbone.js:

Uncaught TypeError: Cannot use 'in' operator to search for 'id' in easy
_.extend.setbackbone.js:205
Backbone.Modelbackbone.js:142
Gamegames.js:13
(anonymous function)games.js:34
jQuery.Callbacks.firejquery.js:1047
jQuery.Callbacks.self.fireWithjquery.js:1165
jQuery.extend.readyjquery.js:436
DOMContentLoadedjquery.js:924

Here is the code, games.js.coffee

jQuery ->
  root = global ? window
  class Game extends Backbone.Model
    initialize: (@n, @diff) ->
      console.log "--> Game.initialize()"
    difficulty: ->
      @diff
    name: ->
      @n
  # Make class Game globally available
  root.Game = Game
  my_game = new Game('easy', 'hard')
  console.log "my_game.name(), my_game.difficulty() --> #{my_game.name()}, #  {my_game.difficulty()}"

I am missing something, but having trouble figuring out what…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:53:15+00:00Added an answer on May 28, 2026 at 7:53 pm

    Backbone model constructor functions expect a dictionary object with keys and values that will be set on that model. You didn’t provide an object, and instead provided 2 strings. The error is cause by backbone trying to iterate through the object, but explodes because you can’t legally do for (key in "easy").

    You also shouldn’t be using properties for model data. You should be using an object on instantiation or set() and get(). So, if I may correct your code:

    jQuery ->
      root = global ? window
      class Game extends Backbone.Model
        initialize: ->
          console.log "--> Game.initialize()"
        difficulty: ->
          @get 'diff'
        name: ->
          @get 'n'
      # Make class Game globally available
      root.Game = Game
      my_game = new Game n: 'easy', diff: 'hard'
      console.log "my_game.name(), my_game.difficulty() --> #{my_game.name()}, #{my_game.difficulty()}"
    

    See this example working here: http://jsfiddle.net/NMkna/

    Note how we no longer accept arguments in initialize now. We can rely on backbone to set the proper attributes in the model, because we now pass in an object when creating the game. And the methods we define simply @get 'propname' in order to retrieve those values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building my first app on Heroku and learning how to use rails
I'm currently learning rails by creating a simple project management app. I've gotten to
Im learning Rails by building apps. I want to make my first authenticated app:
In my rails app I use the validation helpers in my active record objects
I am creating a new rails app as a learning project. I have already
I'm starting learning Ruby on Rails. So my application, like every Rails app, has
Thanks for looking. I am learning rails and am building a web app. I
I'm learning Rails, and got into a little problem. I'm writing dead simple app
I'm kind of new to rails - I'm currently learning by developing a web-app,
do you use Heroku to write Ruby on Rails app? i read about from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.