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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:36:35+00:00 2026-06-14T14:36:35+00:00

Google is not being helpful trying to find the answer to this question! :(

  • 0

Google is not being helpful trying to find the answer to this question! 🙁

How do I properly reference this.colour from the parent object from within a jQuery function like this:

var obj = {
 colour: 'blue',
 do: function() {
  $.getJSON('getcolour.php', function(resp) {
    if (resp.colour == this.colour) { //<== this.colour doesnt = blue
     //match
    }
  });
 }
}
  • 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-14T14:36:36+00:00Added an answer on June 14, 2026 at 2:36 pm

    You need to obtain a reference to this outside of the call to $.getJSON:

    do: function() {
        var self = this;
        $.getJSON('getcolour.php', function(resp) {
            if (resp.colour === self.colour) {  // use "self"
                // ...
            }
        });
    }
    

    alternatively, on ES5 browsers, use .bind to set the context of the inner callback to this:

    do: function() {
        $.getJSON('getcolour.php', function(resp) {
            if (resp.colour === this.colour) {
                // ...
            }
        }).bind(this);  // set the callback's context
    }
    

    jQuery’s $.proxy() function can also be used on earlier browsers to achieve the same effect.

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

Sidebar

Related Questions

Drawing a blank on this, and google was not helpful. Want to make a
I tried searching in google but could not find any useful answer, if(verifier.length() >
This is the first question I have found myself not being able to get
Google is not being very helpful here. I'd like to compose emails with :set
This question flows from the answer to: How does one set up multiple accounts
I've been looking for about an hour now, google is not being my friend.
I see a similar question in Problems while saving a pre-persisted object in Google
Everybody seems to find it in this address ~/Library/Application Support/Google/Chrome/Default/Extensions, however, for some reason
I feel incredibly stupid for not being able to figure this out, but I
I am not being able to import com.google.gwt.view.client.ListViewAdapter;. I have GWT 2.1 and it

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.