473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Nested objects with Javascript using prototype

Hello there,

I am a programmer mostly using c# and just started using Javascript.

I am trying to use prototype to declare and use an object and having
difficulties in coding for nested objects.

Basically my object called layercontrol will contain and array of
layergroup which in turn contains map layer objects. The layergroup
and layer object should be just like any object of properties and
methods.

I should be able to access each layergroup in my object and within
each layergroup, I should be able acess each layer object.

the concept is simple, but am jut struggling !!

Any help from you guys is most welcome.

look forward to hearing from you.

Thank you very much in advance.
Aug 31 '08 #1
1 5380
On Sep 1, 8:26*am, "p.til...@googlemail.com" <p.til...@googlemail.com>
wrote:
Hello there,

I am a programmer mostly using c# and just started using Javascript.

I am trying to use prototype
If you are talking about the general purpose (and confusingly named)
library called Prototype.js, do not use it if your intention is to
learn javascript. If you get bogged down in its Class.create function
you'll be learning a pattern peculiar to Prototype.js and not
particularly useful outside it.

to declare and use an object and having
difficulties in coding for nested objects.
If you want to declare a nested object, you can use an object literal:

var obj = {outer:
{innerString: 'hey', func: function(){}
}
};

Which declares a single object with one property called outer. It's
value is a reference to another object with two properties: one called
innerString with a value that is a string and another called func
whose value is a refernce to a function.

Objects in javascript are essentially bundles of named properties.
There are a few rules on what you can use for names, the properties
can be pretty much anything including primitives, other objects,
arrays, functions and so on.

Why not post a bit more about what you are trying to do and what
you've tried so far?

Basically my object called layercontrol will contain and array of
layergroup which in turn contains map layer objects. The layergroup
and layer object should be just like any object of properties and
methods.
Hmm, don't have much time to help you here but try the pattern here:

<URL: http://www.crockford.com/javascript/private.html >
Of course there are many ways to approach a solution, that is just
one.

I should be able to access each layergroup in my object and within
each layergroup, I should be able acess each layer object.
You can use closures to reference the "private" parts and use public
or privileged functions as getters and setters. Have a go at a simple
case and let's see what comes up. :-)
--
Rob
Sep 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: relaxedrob | last post by:
Howdy All! I am still getting my head around a few base concepts. Any comments or criticisms on the below definitions would be most welcome! A function is an object. JavaScript objects have...
8
by: Thomas Mlynarczyk | last post by:
Hi! If A is an object, then "B = A;" will just assign a reference. Isn't there a simple way to create an actual copy of A and assign that to B? Greetings, Thomas
5
by: TheKeith | last post by:
I can't figure out why this doesn't work: --------------------------------------------- greeting = new Array(); greeting = "hey"; greeting = "bye"; trace(greeting + greeting);
16
by: gabon | last post by:
Due a big project I would like to create different javascript classes and assign them to divs. But how? :) I know the usage of prototype but given that this could be possible: function...
2
by: danny.dion | last post by:
Hi ! I have a question about JScript : I have an object class wich dynamically creates a control in the page. Then it binds an event to that control, pointing on one of its methods (the...
1
by: petermichaux | last post by:
Hi, I have searched the archives but didn't find the questions and answers I am looking for. I have been looking at Prototype.js quite a bit lately as I need to create a very small library of...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
15
by: timothytoe | last post by:
Situation: I have an array of objects. I want to find the maximum value of a given numeric value that exists in each of the objects. Suppose the array of objects is called "stat" and the numeric...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.