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: hakan at backbase.com (Hakan M (Backbase))
  • Subject: [Javascript] Firefox and Custom classes
  • Date: Wed May 18 09:23:47 2005

 > 	obj = firstEle.getAttribute("myAttribute");

This line sets obj to the value returned by 
firstEle.getAttribute("myAttribute"), thus discarding previous declarations.

 From MSDN, regarding getAttribute:
Variant that returns a String, number, or Boolean value as defined by 
the attribute. If the attribute is not present, this method returns null.

In short, obj is no longer an instance of your MyClass, and the fact 
that it's working in IE for you is more surprising to me than that it's 
not working in Firefox.

Regards,
H

amol k wrote:
> 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
> _______________________________________________
> Javascript mailing list
> Javascript@xxxxxxxxxx
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 
>