Because you are binding the click event to the button and not your object

cheers

Michael Lawson
Development Lead, Global Solutions, ibm.com
Phone:  1-276-206-8393
E-mail:  mjlaw...@us.ibm.com

'Whether one believes in a religion or not,
and whether one believes in rebirth or not,
there isn't anyone who doesn't appreciate kindness and compassion..'


                                                                       
  From:       "#micah" <micah.a.sm...@gmail.com>                       
                                                                       
  To:         "jQuery (English)" <jquery-en@googlegroups.com>          
                                                                       
  Date:       07/30/2009 03:45 PM                                      
                                                                       
  Subject:    [jQuery] jQuery and the 'this' keyword                   
                                                                       






I've created a javascript object like so:

var myObj={
     //    internally used
     OtherFunction: function(){ alert('hi');},

     //    externally used
     EditInfo: function(){
           this.OtherFunction();
     }
};

if i bind EditInfo to a button, like so:

$('#myButton').click(myObj.EditInfo)

Then (this) is pointing to the button, not to myObj. Why is that?

I'm using FF3.5

<<inline: graycol.gif>>

<<inline: ecblank.gif>>

Reply via email to