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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:04:50+00:00 2026-05-29T07:04:50+00:00

I have JavaScript class: <html> <head> <script src=MicrosoftAjax.js type=text/javascript></script> <script src=jquery-1.6.4.min.js type=text/javascript></script> </head> <body>

  • 0

I have JavaScript class:

<html>

<head>
    <script src="MicrosoftAjax.js" type="text/javascript"></script>
    <script src="jquery-1.6.4.min.js" type="text/javascript"></script>

</head>

<body>

<script type="text/javascript">

var ClientControl = function () {
    //some instance-specific code here
};

ClientControl.prototype = {
    initialize: function () {
        this.documentClickedDelegate = $.proxy(this.documentClicked, this);
        //this.documentClickedDelegate = Function.createDelegate(this, this.documentClicked); // from MicrosoftAjax
    },

    bind: function() {
        $(document).bind("click", this.documentClickedDelegate);
    },

    unbind: function() {
        $(document).unbind("click", this.documentClickedDelegate);
    },

    documentClicked: function() {
        alert("document clicked!");
    }
};

var Control1 = new ClientControl();
Control1.initialize();
var Control2 = new ClientControl();
Control2.initialize();

Control1.bind();
Control2.bind();

Control1.unbind();
//Control2`s documentClickedDelegate handler, if created with $.proxy, already is unbound!

</script>
</body>
</html>

So the problem is, when unbind() method of FIRST Control1 object is called, it unbinds BOTH documentClickedDelegate handlers of both objects, if they are created with $.proxy() method.
So jquery event system thinks that these handlers are same, despite different contexts passed to $.proxy() method.

If documentClickedDelegate handlers are created with Function.createDelegate – MicrosoftAjax Library`s method, everything workds fine. Handlers are different.

Turned out that $.proxy creates identical proxy functions for different contexts passed. From official site:

“Be aware, however, that jQuery’s event binding subsystem assigns a
unique id to each event handling function in order to track it when it
is used to specify the function to be unbound. The function
represented by jQuery.proxy() is seen as a single function by the
event subsystem, even when it is used to bind different contexts. To
avoid unbinding the wrong handler, use a unique event namespace for
binding and unbinding (e.g., “click.myproxy1”) rather than specifying
the proxied function during unbinding. “

Which in my case shoudn`t be done, because namespaces separate type-specific events, not instance-specific.

Here are screenshots, where you can see, that $.proxy creates handlers with identical GUID = 1, and Function.createDelegate creates handlers with DIFFERENT GIUDs: guid = 1 and guid = 2.

enter image description here

enter image description here

enter image description here

enter image description here

So when deleting one in first case, it deledes both, which should NOT be done!

My question is: is there any analog in jquery to Function.createDelegate? I don`t want to use whole another MicrosoftAjax library for only one feature.
Or maybe any general solution to this problem – how to tell jquery that handlers are different. Thank you for your answers.

  • 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-29T07:04:51+00:00Added an answer on May 29, 2026 at 7:04 am

    You do need to namespace the events. Simple example:

    var counter = 0;
    
    ClientControl.prototype = {
        initialize: function () {
            this.documentClickedDelegate = $.proxy(this.documentClicked, this);
            this.num = counter++;
        },
        bind: function() {
            $(document).bind("click.proxy" + this.num, this.documentClickedDelegate);
        },
        unbind: function() {
            $(document).unbind("click.proxy" + this.num, this.documentClickedDelegate);
        },
        documentClicked: function() {
            alert("document clicked!");
        }
    }
    

    Here’s a working version. Click anywhere on the document and you get one alert. Without the namespacing you get 2.

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

Sidebar

Related Questions

I have the following code: <html> <head> <script type=text/javascript language=javascript src=jquery/jquery-1.5.1.js></script> <script type=text/javascript language=javascript
I have a page as below: <head> <script type="text/javascript" src="jquery-1.6.1.js"></script> <script type="text/javascript"> $(document).ready( function()
Here's my code: <!doctype html> <html> <head> <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <style type=text/css> label {display:block;
I've got the following in my <head> section: <script type=text/javascript> $(function(){ $(h5).live(click, function(){ alert($(this).tmplItem());
I have a number of elements with the same class like this: <html> <head><title>example</title>
I have some JQuery code that converts all HTML elements of a specific class
I have a JavaScript class that I have made and put it into its
I have some javascript that goes out and fetches a javascript class on another
I have a javascript function (class) that takes a function reference as one paremter.
Is there a best-practice or common way in JavaScript to have class members as

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.