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> Link to comment https://forums.phpfreaks.com/topic/153807-solved-thisvalue-is-undefined/ 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! Link to comment https://forums.phpfreaks.com/topic/153807-solved-thisvalue-is-undefined/#findComment-808358 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.