Simple answer, don't use an array as an "associative array"; use an Object. Arrays aren't supposed to be used as you're using them. It's not a prototype issue.
If you want the details, do a group search, you'll find many posts on the subject. On 12/27/07, Daanoz <[EMAIL PROTECTED]> wrote: > > today i was working some javascript when my array's didn't behave as > expected, so after some research i found prototype was the cause... > try my test to see what i mean, so my question is, how can i loop > associative array (so i can get all keys for the array) without > prototype giving me all functions? > > Test HTML: > > ************************************************************************************* > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http:// > www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml" lang="nl" xml:lang="nl"> > <head> > <title>Test HTML</title> > <meta name="description" content="" /> > <meta name="keywords" content="" /> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > <script src="prototype.js" type="text/javascript"></script> <!-- > Prototype JavaScript framework, version 1.6.0 --> > <script type="text/javascript"> > > function CTest() > { > this.aTest = new Array(); > this.aTest["key1"] = "val1"; > } > > CTest.prototype.printArray = function() > { > var PrintOut = "<table>"; > > for(x in this.aTest) { > PrintOut += "<tr><td>" + x; > PrintOut += "</td><td>"; > PrintOut += this.aTest[x]; > PrintOut += "</td></tr>"; > } > > PrintOut += "</table>"; > document.getElementById('result').innerHTML = PrintOut; > } > > var Test = new CTest(); > </script> > </head> > <body> > <div onclick="Test.printArray()">clickme</div> > <div id="result"></div> > </body> > </html> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
