Jump to content

[SOLVED] this.value is undefined


The Little Guy

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.