There is a new love named "jQuery" but I still have some problems in understanding issues totally (maybe like in real life ;) Coming from C++ it takes some effort in dealing on the (totally other) javascript OOP. The code below (that represents basics of a quite more complex issue ...) runs fine, but it gives me some headaches.
--------- <!DOCTYPE html> <html> <head> <title>jQuery OOP</title> </head> <script type="text/javascript"> var data_at_startup = "" + // 1 paragraph at startup "<p>some content</p>"; var data_out_of_an_AJAX_call = "" + // 3 paragraphs later (out of an AJAX-call) "<p>other content</p>"+ "<p>other content</p>"+ "<p>other content</p>"; MyDivObject = new MyDivClass; function MyDivClass() { this.Show = function(txt) { $("#MyDiv").html(txt).click( function() { // Simulation of an AJAX-call MyDivObject.Show( data_out_of_an_AJAX_call ); }); } } </script> <body> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script> $(function() { MyDivObject.Show(data_at_startup); }); </script> <div id="MyDiv"></div> </body> </html> ------ What I do: In my try to encapsulate jQuery-Code in classes/objects I declare "MyDivClass". Later an object of this type has to manage contents of the div container <div id='MyDiv'>. At the beginning it simply has to exposure one paragraph (= data_at_startup). MyDivObject.Show( data_at_startup ); Adding some jQuery-Code to capture "click"-events on its paragraphs $("#MyDiv").html(txt).click( function() has to run in AJAX-calls (later) to updates parts of - or all of - MyDiv's content (for simplification in the demo I call the Show() method just with static data ( = data_from_AJAX_call); MyDivObject.Show ( data_from_AJAX_call ) it works ... but I cannot look behind the scenes: Isn't there some kind of recursion in calling ".Show(...)" ? MyDivObject = new MyDivClass; function MyDivClass() { this.Show = function(txt) { ... MyDivObject.Show(...) ... I'm surprised because it seem to work fine, but ... is it acceptable code ... or do I run into problems by coding this way? Do I get (whatever) problems in doing it this way ? What should I read & learn to close the knowledge leak in my mind ;) ? thanks in advance fran -- View this message in context: http://old.nabble.com/jQuery-%2B-OOP-%2B-AJAX-tp26945051s27240p26945051.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.