[Javascript] Firefox and Custom classes

amol k amol.forums at gmail.com
Wed May 18 09:03:07 CDT 2005


I have a custom class in javascript which works flawlessly in IE but
not in Firefox.
(I am new to firefox targeted front end development)
The class is pretty complicated but here is a simple code that
illustrates the problem I am facing.

<html>
<head>
<script>
function MyClass() { this.compute=compute; }

function compute(a, b){	alert(a+b); }

function illustrate_error() {
	var firstEle = document.getElementById("first");

	var obj = new MyClass();
	firstEle.setAttribute("myAttribute", obj);

	obj = firstEle.getAttribute("myAttribute");
	obj.compute(2,2); // line that creates the error
}
</script>
</head>
<body>
<table>
	<tr>
		<td id="first">hi</td>
		<td id="second">there</td>
	</tr>
	<tr>
		<td><input type="button" value="Illustrate Error"
onclick="javascript:illustrate_error();"/></td>
	</tr>
</table>
</body>
</html>

This code works in IE but not in firefox. (I get "obj.compute is not a
function" error)  I tried variations of this code like replacing
this.compute=compute with MyClass.prototype.compute=compute, etc.
Firefox version: Gecko/20050414 Firefox/1.0.3

Any pointers?

Thanks,
Amol



More information about the Javascript mailing list