Javascript objects notes
There's no native size function.
Cookies saved shouldn't exceed 4093 bytes, thus we need to ensure we don't have an object of bigger size.
This stackoverflow answer checks the estimated size of the object
AKA: Using object constructor.
By letting values/keys get decided later in the code
var data = {};
data.first_name = 'Ahmed';
data.last_name = 'Adel';
data.email = 'ahmed.adel@domain.c';
AKA: Using object literals.
By setting up values/keys up front while declaring the object
var data = {
data.first_name = 'Ahmed',
data.last_name = 'Adel',
data.email = 'ahmed.adel@domain.c'
};
Note: we may extend that for a more OO way so that we could template objects.
In example, by using data as a function and calling new on it for every object.
function datum(first_name, last_name, email)
{
this.first_name = first_name,
this.last_name = last_name,
this.email = email
}
data =new datum(first_name, last_name, email);
This way is similar to the first one, but a bit more dynamic
var data = {};
data['first_name'] = 'Ahmed';
data['last_name'] = 'Adel';
data['email'] = 'ahmed.adel@domain.c';
In example: if we have dynamic property name we may do
function datum(first_property, second_property, third_property, val1, val2, val3)
{
var data = {};
data[first_property] = val1;
data[second_property] = val2;
data[third_property] = val3;
return data;
};
data = datum(first_name, last_name, email, 'Ahmed', 'Adel', 'ahmed.adel@domain.c');
Stackoverflow question.
At this moment of video, we can find the technical namings.
The OOP part of the video goes through this tutorial.