Javascript Headscratcher

Posted by Jason on Stack Overflow See other posts from Stack Overflow or by Jason
Published on 2010-05-05T23:37:12Z Indexed on 2010/05/05 23:48 UTC
Read the original article Hit count: 152

Filed under:
|

I have the following in a javascript file (using jQuery as well):

$(function(){
    $('#mybutton').live('click',myObject.someMethod);
});

var myObject = { 
    someMethod: function() { //do stuff }
};

I get a js error on pageload that says "myObject isn't defined". However, when I change the event handler in the doc.ready function to:

$('#mybutton').live('click', function(){ myObject.someMethod(); });

it works! I have code structured like the first example all over my codebase that works. W T F??

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery