WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 another javascript oop question, sam conrad, October 20, 2003
     Re:another javascript oop question, Erik Arvidsson, October 20, 2003

Subject: Re:another javascript oop question From: Erik Arvidsson Date: October 20, 2003
There is another syntax for creating objects which I think suits your scenario perfectly

var obj = {prop1: "val1", prop2: "val2"};

Using this you can create an array with three objects in it.

var main = [
{text: "Text 1", name: "a"},
{text: "Text 2", name: "b"},
{text: "Text 3", name: "n"}
];

then you can use

main[0].text
main[0].name

I hope that helped a little.

erik



<script>
/* Hi guys!! i am trying to nest objects in an array, such that instead of having to code:
alert(main[2][0].text); to get the property value "B"
i can just code: alert(main[2].text); and get the same results.
I suppose this should be faily simple, but I don't understand oop well enough to know how to do it.
Any suggestions would be greatly appreciated. My simplified example code follows: Cheers!! */
var a = [new function(){this.text="A";}, "A_etc",];
var b = [new function(){this.text="B";}, "B_etc",];
var c = [new function(){this.text="C";}, "C_etc",];
var main = [a, b, c];
// this works:
alert(main[0][0].text);
alert(main[1][0].text);
alert(main[2][0].text);
// would like to be able to code:
alert(main[0].text);
alert(main[1].text);
alert(main[2].text);
</script> /* Hi guys!! i am trying to nest objects in an array, such that instead of having to code: alert(main[2][0].text); to get the property value "B" i can just code: alert(main[2].text); and get the same results. I suppose this should be faily simple, but I don't understand oop well enough to know how to do it. Any suggestions would be greatly appreciated. */ var a = [new function(){this.text="A";}, "A_etc",]; var b = [new function(){this.text="B";}, "B_etc",]; var c = [new function(){this.text="C";}, "C_etc",]; var main = [a, b, c]; // this works: alert(main[0][0].text); alert(main[1][0].text); alert(main[2][0].text); // would like to be able to code: alert(main[0].text); alert(main[1].text); alert(main[2].text);



Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX