You are not logged in.
I'm trying to get into javascript and jquery for a hobby project of mine. Now I've used the last 4 hours trying to find a guide on how to create class objects that can contain the following information
Identification : id
Group : group
Persons : array(firstname : name, lastname : name)
Anyone know of a tutorial that can show me how to do this?
I found this page where I can see that an object can contain an array, but it doesn't state whether it is possible to use a multidimensional array.
And this page just describes the object with normal values.
Any pointers in the right direction are appreciated.
MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage
Offline
There are no classes in JavaScript. It uses a different style of objects and what you found is indeed what you need.
Well, it might help to think about it as a dynamic, runtime-modifiable object system. An Object is not described by class, but by instructions for its creation.
Here you have your object. Note that you can use variables everywhere.
var id = 123;
var test = {"Identification": id,
"Group": "users",
"Persons": [{"firstname":"john", "lastname":"doe"},{"firstname":"jane","lastname":"doe"}]
}
This is identical to the following code. (The first one is a lot nicer, though.)
var id = 123;
var test = new Object();
test.Identification = id;
test["Group"] = "users;
test.Persons = new Array();
test.Persons.push({"lastname":"doe","lastname":"john"});
test.Persons.push({"lastname":"doe","lastname":"jane"});
As you can see, you can dynamically add new properties to an object. You can use both the dot-syntax (object.property) and the hash syntax (object["property"]) in JavaScript.
Offline
Thanks wuischke
That's what I was looking for. It's a lot easier to understand when showed an example.
Ich wünsch dir noch 'nen schönen Tag!
MadEye | Registered Linux user #167944 since 2000-02-28 | Homepage
Offline