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 7592529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:55:47+00:00 2026-05-30T20:55:47+00:00

I made a simple game yesterday in javascript using coffeescript. The bulk of the

  • 0

I made a simple game yesterday in javascript using coffeescript. The bulk of the game runs through a game object which is instantiated after the user submits a form on the page. The form contains variables and options for the game they want to play.

Everything works fine during the game, but when the game is over I have the form appear again and if the user submits the form a second time its supposed to call the same function and overwrite the old game variable with a new instance of the game object, but what I’ve noticed is that its not resetting all the existing variables and paramaters set by the original game object.

Is there any way to fully remove the old object and its parameter when a new one is instantiated?

Here is My object being declared as a ‘class’ in coffeescript.

window.Game   = class Game

  constructor: (options) ->
    players  = options[0] ? '1'
    p1 =  p2 = false
    @player1 = new Player(options[1] ? 'X', p1 )
    @player2 = new Player(options[2] ? 'O', p2 )
    @cells   = ($ "section#board .cell")
    @cells.each ->
      $(@).text(" ")
      $(@).removeClass('score')
    @currentPlayer = @player1
    @availableMoves = 9
    ($ 'section#board div.cell').bind
      click:      @.makeMove
      mouseleave: @.resetCell

    setTimeout(@.computerMove(@currentPlayer), 1000) if parseInt(players) is 0

I’m calling this after form submit through this function.

($ '#gameOptions').submit (event) ->
  event.target.checkValidity()
  event.preventDefault()
  game = new Game [($ '#player-count') .val(), 
                   ($ '#player-1-type').val(),
                   ($ '#player-2-type').val()]

Even when adding a call do delete game before re-instantiating the game object. The ghost variables persist. I posted in coffeescipt for brevity and to increase readability.

  • 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-30T20:55:48+00:00Added an answer on May 30, 2026 at 8:55 pm

    The delete game will not remove the object, only the reference. The problem is that references to the old variable are persisting somewhere. There might be others, but at the very least this part of the constructor is giving you problems:

      ($ 'section#board div.cell').bind
        click:      @.makeMove
        mouseleave: @.resetCell
    

    JQuery is allowing you to bind multiple functions to the same event; in this case, both the old and new functions, and the old ones are holding the reference to the old object. In order to fix this, you should unbind in the form submission function:

    ($ 'section#board div.cell').unbind()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
I made a simple game for the iPhone using OpenGL ES. Everything works fine
I made a simple command-line based game in java, only two classes (using Eclipse).
I recently made a simple game where user can submit his/her high scores online.
On Windows, testing different OSes is made simple using VMs. Is there a simple
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we
I'm teaching myself CSS through books and websites. I've made a simple site with
I made a simple pong game from a tutorial (icode blog)and would like to
I made a basic snake game in a DOS enviroment using turbo C++ 3.0,
I'm writing a simple game with javascript/html5, and I'm trying to implement gravity. The

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.