First off we'll start by creating our object function:
This is a basic layout of a custom object. When creating the function, keep in mind that all the parameters which you want to store data in should be specified in the parentheses (). In this case each person will have their own name and surname, which is sufficient for this tutorial.
Fot those thinking 'whats with this.name = name;'. It doesn't make sense. This isn't as complicated as it looks. 'this' means the current object and because we have this.name, we are specifying the name of the current object and setting it to the name argument, which is found in the parenthesis: function person ( name, surname ). The surname works the same way.
To show how above works, lets initiate this function with different values:
Now we have created three person objects, each with it's own values.
Let's start with variable personOne. Because you set it equal to the person function with the two parameters: 'John' and 'Doe', the method initiates with John as name and Doe as surname.
Now inside the object you say that this. name, which is variable personOne. Thus the name for personOne is John and the surname is Doe.
The second and third objects work in the same manner. The values are sent to the object function and stored in the variables. It doesn't matter how many objects you create, they will all have their own values.
Now to test whether the data has been stored, I will be using alert popups:
As seen above, to display the values in the first popup, I used personOne.name. This will return the name variable inside object personOne object. The output for the first popup looks like so:
Which is what we expect as we sent the values John and Doe to the object function.
Next to check the output for the second popup, which should be the surname 'Bowen':
Lastly we want to output the both name and surname from object personThree:
Now we have created three different custom objects.
If anything is still unclear or if there is something you really want to know, leave a comment.










