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