Re: Storing Objects in an Associative Array (object)

Friday, September 14, 2012

Below is a more specific test case for you. Just copy and paste it into a black HTML document and you will see. =(


<html>
<head>
   
<meta charset="utf-8">
   
<script>
 
var ProcessObjectList = function (inXML)
 
{
 
var arrObjectList = new Object();
 
var objClass    = new clsNewClass();        // see class declaration below
 
 document
.write('<p> <strong> In function POL</strong></p>');
 
 
for (ctr=0; ctr <= 2; ctr++)
 
{
 
if (ctr == 0)
 
{
 objClass
.setName    ('Name 1');
 objClass
.setValue1 ( 1 );
 objClass
.setValue2 ( 2 );
 
}
 
if (ctr == 1)
 
{
 objClass
.setName    ( 'Name 2' );
 objClass
.setValue1 ( 3 );
 objClass
.setValue2 ( 4 );
 
}
 
 
if (ctr == 2)
 
{
 objClass
.setName    ( 'Name 3' );
 objClass
.setValue1 ( 5 );
 objClass
.setValue2 ( 6 );
 
}
 
 arrObjectList
[ objClass.getName() ] = objClass;
 
 document
.write('<p> Name: <strong>' + objClass.getName() + ' </strong></p>');
 
 
} /* end for loop */
 
 
return arrObjectList;
 
} /* end Process Object List */
 
 
 
function clsNewClass()
 
{
 
var Name = '';
 
var Value1 = '';
 
var Value2 = '';
 
 
this.getName = function()        { return Name; }
 
this.getValue1 = function()        { return Value1; }
 
this.getValue2 = function()        { return Value2; }
 
 
this.setName = function(inVal) { Name = inVal; }
 
this.setValue1 = function(inVal) { Value1 = inVal; }
 
this.setValue2 = function(inVal) { Value2 = inVal; }
 
} // end class New Class
 
 
var arrObjList = Object(); // will be used for the associative array
 
 arrObjList
= ProcessObjectList();     // see function declaration below
 
 document
.write('<p> <strong> After Assignment</strong></p>');
 
 document
.write('<p> Name: <strong>' + arrObjList['Name 1'].getName() + '</strong> v1: <strong>' + arrObjList['Name 1'].getValue1() + '</strong> v2: <strong>' + arrObjList['Name 1'].getValue2() + '</strong></p>');
 document
.write('<p> Name: <strong>' + arrObjList['Name 2'].getName() + '</strong> v1: <strong>' + arrObjList['Name 2'].getValue1() + '</strong> v2: <strong>' + arrObjList['Name 2'].getValue2() + '</strong></p>');
 document
.write('<p> Name: <strong>' + arrObjList['Name 3'].getName() + '</strong> v1: <strong>' + arrObjList['Name 3'].getValue1() + '</strong> v2: <strong>' + arrObjList['Name 3'].getValue2() + '</strong></p>');
   
</script>
   
</head>
<body>
</body>

--
 
 

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii