Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Firefox and Custom classes


  • From: amol.forums at gmail.com (amol k)
  • Subject: [Javascript] Firefox and Custom classes
  • Date: Wed May 18 09:09:56 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