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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:06:25+00:00 2026-05-15T03:06:25+00:00

In Javascript I’m trying to pass a class member to a jQuery function, but

  • 0

In Javascript I’m trying to pass a class member to a jQuery function, but somehow the ‘this’ object in that function gets messed up. This is the code:

function Hints() 
    {
    this.markProduct = function() { alert('hi'); };
    this.selectProduct = function() { this.markProduct(); }; 
    }

When I call this code using this:

oHints = new Hints();
oHints.selectProduct();

It works just fine and the ‘this’ object in the ‘selectProduct’ function refers to the Hints object.
But when I try this:

oHints = new Hints();
$('#prodquery').keydown(oHints.selectProduct);

The ‘this’ object in the ‘selectProduct’ function refers to the html object that fired the keydown event.

Does anyone have a clue? I’m puzzled :/

  • 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-15T03:06:26+00:00Added an answer on May 15, 2026 at 3:06 am

    Do this instead:

    $('#prodquery').keydown(function() { oHints.selectProduct() });
    

    And then read this for explanation of how this works in different contexts.

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

Sidebar

Related Questions

JavaScript/JQuery var arr=[]; $('.element').each(function(i) { arr.push({id:i,value:$(this).attr('data-value')}); }); $.get('/json.php?arr='+arr,function(result) { alert(result); }); PHP <?php $j
Javascript functions can be declared on a objects prototype like this: <object name>.prototype.<variable name>=function(){
javascript with> var customer=document.getElementById('custList').value; and that works... Why does it work BUT... var customer=(form1.custList.value);
Javascript jQuery event handling If on event (for example 'click') bound one function for
JavaScript (jQuery) function display_youtube(new_url) { $('#movie_url').removeAttr('value'); $('#embed_url').removeAttr('src'); $(document).ready(function() { $('#movie_url').attr('value', new_url); $('#embed_url').attr('src', new_url); $('#shade').css('display',
JavaScript is known to be single-threaded in all modern browser implementations, but is that
Javascript passes objects by reference. This makes perfect sense. But once you start manipulating
Javascript/JQuery noob here, so apologies. I'm using .ajax to get a JSON object then
Javascript has built-in function for time where var date = new Date(); d.getHours() //gets
JavaScript object created with a prototype maintains live connection to its prototype, so that

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.