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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:54:03+00:00 2026-06-10T15:54:03+00:00

I am trying to use this.moveCursor with Backbone, but it says it is undefined

  • 0

I am trying to use this.moveCursor with Backbone, but it says it is undefined when I console.log. The method is obviously defined so I am not sure what is wrong here.

At first I though it was because of this. and the switch statement not returning.

However, even when I console.log outside the switch statement, it the same.

Can anyone help?

setup: function(){      
        $(document).on('keydown', this.keyCode);
},

keyCode: function(e){
                switch(e.keyCode) {
                    case 37:  console.log(this.moveCursor(-1,0)); break; //undefined
                    case 38:  return this.moveCursor(0,-1); break;
                    case 39:  return this.moveCursor(1,0); break;
                    case 40:  return this.moveCursor(0,1); break;
                    case 32:  return play.selectBlock(); break;
                    case 13:  return play.selectBlock(); break;
                };

        console.log(this.moveCursor()); //undefined
            }, 



   moveCursor: function(x, y){
                    var cursorSelected = play.get('cursorSelected'),
                        cursorX = play.get('cursorX'),
                        cursorY = play.get('cursorY');



                console.log('moveCursor');

                if(cursorSelected){
                    x += cursorX;
                    y += cursorY;

                    this.getBlock(x,y);
                } else {
                    //
                }
            },
  • 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-10T15:54:04+00:00Added an answer on June 10, 2026 at 3:54 pm

    You have a context issue. The this keyword will represent the caller of the keyCode() function, no matter where the keyCode() has been defined into.

    To know more about this try to console.log( this ), it will show you what it really this in that moment of the execution.

    To solve this issue you can play with _.bindAll().

    If the keyCode() is a handler of a Backbone.View.events the binding should be already done.

    Update

    I see the keyCode() is a handler of a normal jQuery event:

    $(document).on( 'keydown', this.keyCode );
    

    The _.bindAll() will work for it, also you can use a jQuery.proxy() like this:

    $(document).on( 'keydown', $.proxy( this.keyCode, this ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to use this method to make my characters but i get the
im trying to use this method to make my characters but i get the
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I'm trying to use this to create a splash screen, but I only get
I'm trying to use this solution but Eclipse still cant resolve Attachment and DataService.
I'm trying to use this thumbnail generator, but as you can see you have
I am trying to use this UrlHelper extension method: public static string ToPublicUrl(this UrlHelper
So i'm trying to use this method to load a certain theme based on
I'm trying to use this layout with two 50% column width instead. But it
I am trying to use this query upon my Android database, but it does

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.