The Little Guy Posted April 13, 2009 Share Posted April 13, 2009 I have this class: function Class(o){ var objct = o; var obj; this.method = meth1; } function meth1(e){ alert(this.objct); } When I click on the document, the alert says "undefined" why? It should say jObject, since that is what was passed to "Class". <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Example 1</title> <script type="text/javascript" src="test.js"></script> <script type="text/javascript"> var myClass = new Class('jObject'); </script> </head> <body onclick="myClass.method(event);"> <div id="jObject" class="width100">Click Somewhere in the document!</div> </body> </head> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 13, 2009 Author Share Posted April 13, 2009 Ah ha! I was defining the variables wrong! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.