JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 22nd, 2008, 01:46 PM
Knat Knat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 15 Knat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 12 m 25 sec
Reputation Power: 0
Prototype "extending" my array problem.

I have the following code
Code:
<html>
<head>
<script type="text/javascript" src="cropper/lib/prototype.js" language="javascript"></script>
<script>

function showArray(inArray)
{
   var retString="";
   for(var item in inArray)
   {
      retString+=inArray[item];
   }
   return retString;
}

function arrayTester()
{
   testArray=new Array();
   testArray["val1"]="Value 1";
   testArray["val2"]="value 2";
   outputString=showArray(testArray);
   document.getElementById("output").innerHTML=outputString;
}

</script>
</head>
<body>
<div id="output"></div>
<script>arrayTester();</script>
</body>
</html>


When it executes it outputs tons and tons of prototype garbage in addition to my array. Apparently prototype "extends" any array that is created. Is there any way to stop this from happening?

Reply With Quote
  #2  
Old February 22nd, 2008, 01:57 PM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 2,056 Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced Folder
Time spent in forums: 2 Weeks 3 Days 7 h 58 m 28 sec
Reputation Power: 1319
What browser are you using? It works for me in IE6.

maybe i just don't use arrays enough in JS, but shouldn't "val1" and "val2" be numbers or variables? I know what you have works (in IE 6 at least) but i've just not seen that done before.
__________________
Three gigs for the secretaries fair
Seven gigs for the system source
Nine gigs for the coders in smoky lairs
One disk to rule them all, one disk to bind them
One disk to hold the files, and in the darkness grind'em
---------------------------------------------------
It is by caffeine alone that I set my mind in motion.
It is by the beans of Java, that my thoughts acquire speed.
The hand acquire shakes; the shakes become a warning.
It is by caffeine alone that I set my mind in motion.

Reply With Quote
  #3  
Old February 22nd, 2008, 05:06 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,835 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 22 h 1 m 5 sec
Reputation Power: 4192
Only use an array if you want numerical indexes.

For an associative array, use an object.
Code:
   var testArray=new Object();

The language attribute of the <script> element is deprecated. Just use the type attribute.
Comments on this post
Ebot agrees!
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Last edited by Kravvitz : February 23rd, 2008 at 11:49 PM. Reason: typo correction

Reply With Quote
  #4  
Old February 23rd, 2008, 06:01 PM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 2,056 Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)Ebot User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced FolderFolding Points: 87885 Folding Title: Advanced Folder
Time spent in forums: 2 Weeks 3 Days 7 h 58 m 28 sec
Reputation Power: 1319
I knew you would have the answer!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Prototype "extending" my array problem.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap