[Javascript] Firefox and Custom classes

amol amol.forums at gmail.com
Wed May 18 09:39:34 CDT 2005


Thanks.
Makes sense.
It was stupid on my part but your reply helped me think fresh. Problem 
solved.


Hakan M (Backbase) wrote:

> >     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 at LaTech.edu
>> https://lists.LaTech.edu/mailman/listinfo/javascript
>>
>>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>




More information about the Javascript mailing list