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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:58:17+00:00 2026-06-11T18:58:17+00:00

function myClass(myobject){ var myclass = {}; myclass.registerEvent = function(){ $(‘#’+myobject.id).live(‘someEventThatTriggersRightAway’, runMe); }; runMe =

  • 0
function myClass(myobject){
      var myclass = {};

      myclass.registerEvent = function(){
          $('#'+myobject.id).live('someEventThatTriggersRightAway', runMe);
      };

      runMe = function(){
            $('#'+myobject.id).die('someEventThatTriggersRightAway', runMe);
            console.log("Hello "+myobject.name);
      };

      return myclass;
}


var instance1 = new myClass({id:'button1',name:'MATO'});
var instance2 = new myClass({id:'button2',name:'YAMA'});

when i run this code

instance1.registerEvent();

the result is

Hello YAMA

it is as if the first instance had been overwritten by the 2nd one. I can solve this if only i can pass the ‘myobject’ in the event’s callback, but i dont know how to do it. and also i cant kill it if it has parameters. how can i do this?

Thank you!

  • 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-11T18:58:18+00:00Added an answer on June 11, 2026 at 6:58 pm

    You have missed the var from runMe, so runMe is leaking to the global execution context. Therefore, each time you call myClass, the reference to myobject in runMe is going to change.

    var runMe = function(){
        $('#'+myobject.id).die('someEventThatTriggersRightAway', runMe);
        console.log("Hello "+myobject.name);
    };
    

    Here’s a working example.


    Side note: are you aware that the jQuery .live() and .die() methods are deprecated? You should be using .on() (jQuery 1.7+) or .delegate() instead.

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

Sidebar

Related Questions

class MyClass { function __constructor($A,$B,$C) { echo($A $B $C); } } $MC=new MyClass('Hello','World','!'); My
I created a javascript class as follow: var MyClass = (function() { function myprivate(param)
When the myClass function returns a single string hii, testClass.getDetails() works fine: function myClass(name,
I have a custom class that looks like: function myClass(){ var thing; var thingtype;
I have created a class like so: function MyClass() { var myInt = 1;
function MyClass(projectName) { this.projectName = projectName; } MyClass.prototype.createHttpRequestObject = function() { /* do something
I have a class, looks something like this: function MyClass() { this.array1 = [];
I'm having trouble with the MyClass::function(); style of calling methods and can't figure out
I have this static callback function in MyClass, and I try to call another
I have some filters expressed as a list of function List(MyClass => Boolean) .

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.