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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:35:10+00:00 2026-05-23T08:35:10+00:00

Here is what i cannot get to work – in mouseMove this.mouseX is undefined.

  • 0

Here is what i cannot get to work – in mouseMove this.mouseX is undefined. I need the mouseX and mouseY (e.pageX in code) from mousemove event.

function myClass () {
    var mouseX=x;
    var mouseY=y;
    $(document).mousemove(this.mouseMove);
}
myClass.prototype.mouseMove = function(e){
    this.mouseX=e.pageX;//not a good idea but you can alert this
}
var a=new myClass();

Can i get that event passed to the supposed class instance or there is no way to get it done?

I should also mention i am trying to avoid global scope variables here.

  • 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-23T08:35:10+00:00Added an answer on May 23, 2026 at 8:35 am

    Two three things:

    var mouseX only declares a variable local to the myClass function. You have to declare a property of the instance with this.mouseX (this refers to the current instance):

    function myClass () {
        this.mouseX=x;  // where do x and y come from?
        this.mouseY=y;
        //...
    }
    

    Secondly, make sure you pass x and y as parameters to the constructor. Otherwise you will get an error (if they are not defined in higher scope, but that does not seem useful to me).

    Thirdly, if you just pass this.mouseMove as event handler, inside the event handler, this will refer to window and not to the myClass instance. Use $.proxy to set the context of the callback explicitly:

    function myClass(x, y) {
        this.mouseX=x;
        this.mouseY=y;
        $(document).mousemove($.proxy(this.mouseMove, this));
    }
    

    I suggest to read MDC – Working with objects.

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

Sidebar

Related Questions

Try as I might, I cannot get this to work. Here is my latest
I cannot get this to work. I want to use str_to_date to convert a
This should be dead simple, but I cannot get it to work for the
Ok, I've tried about near everything and I cannot get this to work. I
I cannot get this to work so I thought it might be a wise
I cannot get this crazy dependency to work and please don't tell me to
I realize that a whole lot of code cannot fit here, but I am
I have a quite simple scenario that I cannot get to work correctly. I
I cannot get interception to work with Prism v2 (Oct 2009). I am trying
I have a pretty simple setup that I cannot get to work in silverlight.

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.