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

  • Home
  • SEARCH
  • 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 8566747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:43:35+00:00 2026-06-11T17:43:35+00:00

I have a weird issue with this code Moonbeam.Input.KeyboardState = function Moonbeam_Input_KeyboardState() { this._keys

  • 0

I have a weird issue with this code

Moonbeam.Input.KeyboardState = function Moonbeam_Input_KeyboardState() {
    this._keys = new Array(2);
    this._resetKeys(); 
    } 

    Moonbeam.Input.KeyboardState.prototype = {

    _resetKeys: function Moonbeam_Input_KeyboardState$_resetKeys() {
        this._keys.clear();
    },

    _SetKeys: function Moonbeam_Input_KeyboardState$_SetKeys(keysPressed) {
        this._resetKeys();
        this._keys = keysPressed;
    }
}

I call the _SetKeys function and pass in a value, on the line this._resetKeys(); KeysPressed contains the value, on the line this._keys = KeysPressed, after returning from the call to _resetKeys(), keysPressed contains no value.

this is not the behaviour I expect, but javascript is not my speciality.

Can anyone tell me is this something I am doing wrong?

Is this how javascript works – I dont see how you could do recursion if it is.

I have also tried adding the line var _keysPressed = keysPressed; before the call to this._resetkeys() in the _SetKeys function but that also loses its value.

How do I get my values to stay during a call to another function?

stu.

  • 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-06-11T17:43:36+00:00Added an answer on June 11, 2026 at 5:43 pm

    When you pass an array (or object parameter) to a function, it is not copied, the function receives a reference to that array. When you then do this._keys = keysPressed;, _keys contains that same reference. When you later do this._keys.clear();, you’re modifying that array.

    I suspect what’s happening is that you’re calling _setKeys() with the same array as the previous call. So when it calls this._resetKeys(), it clears that array.

    You either need to create new arrays as you need them, perhaps by copying them when receiving them as parameters or returning them as values.

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

Sidebar

Related Questions

I have a rather weird issue. I have an array of html-code in string-format
I'm fairly new to SVN and I have a weird behavior issue. I'm working
This is a weird issue. I have created a view controller with a nib
I'm running a weird issue here. I have code that makes jquery ajax calls
I have this weird issue. I am trying to create a service that synchs
I've got a weird linker issue. I have code that looks like so: double
I'm seeing a really weird issue with this code and sample execution: https://gist.github.com/720278 The
This is a weird issue. I have a List view with 2 Link buttons.
I'm facing this weird issue with Scripting.Dictionary object in my VBA code. I wish
I have a weird issue with firebug with my current javascript code I have

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.