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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:34:37+00:00 2026-05-16T00:34:37+00:00

I was reading the api about jQuery.proxy() . It looks promising but I was

  • 0

I was reading the api about jQuery.proxy(). It looks promising but I was wondering in what situation is this best use. Can anyone enlighten me?

  • 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-16T00:34:37+00:00Added an answer on May 16, 2026 at 12:34 am

    When you want a function that has the this value bound to a specific object. For example, in callbacks such as event handlers, AJAX callbacks, timeouts, intervals, custom objects, etc.

    This is just a manufactured example of a situation where it might be useful. Assuming there is a Person object which has a property name. It is also linked to a text input element, and whenever the input value changes, the name in this person object gets updated too.

    function Person(el) {
        this.name = '';
    
        $(el).change(function(event) {
            // Want to update this.name of the Person object,
            // but can't because this here refers to the element
            // that triggered the change event.
        });
    }
    

    One solution that we often use is to store the this context in a variable and use that inside the callback function such as:

    function Person(el) {
        this.name = '';
    
        var self = this; // store reference to this
    
        $(el).change(function(event) {
            self.name = this.value; // captures self in a closure
        });
    }
    

    Alternatively, we could have used jQuery.proxy here so the reference to this refers to the object of Person instead of the element that triggered the event.

    function Person(el) {
        this.name = '';
    
        $(el).change(jQuery.proxy(function(event) {
            this.name = event.target.value;
        }, this));
    }
    

    Note that this feature has been standardized into ECMAScript 5 which now includes the bind method borrowed from prototypejs and is already available on some browsers.

    function Person(el) {
        this.name = '';
    
        $(el).change(function(event) {
            this.name = event.target.value;
        }.bind(this)); // we're binding the function to the object of person
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a little bit about the eBay API, but I can't find anything
I was reading jQuery's page for animate() http://api.jquery.com/animate/ Its examples don't mention about if
I have this situation where I am reading about 130K records containing dates stored
I was reading about FB Graph API in this page. Please see the section
I've been reading about the jQuery template plugin http://api.jquery.com/tmpl/ as a means of binding
After reading about Firefox's Geolocation functionality, which doesn't use GPS , I'm wondering what
when reading a python ndb api of google app engine, I cam across this
I've trying to use the API for CapsuleCRM... http://capsulecrm.com/help/page/api_gettingstarted I've been reading some articles
OK, this is basically just about any non-default OS API running on all different
I have been reading about how the dojo 1.7 loader uses an AMD API/framework

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.