WEBVTT

00:01.140 --> 00:06.210
In previous video, we have learned about what an object is and we have used constructor notation method

00:06.210 --> 00:12.410
to create that, but as I remember, we said that it's not the preferred method in real life.

00:13.080 --> 00:17.550
There is a better, more convenient and much quicker way to create objects.

00:17.550 --> 00:19.270
And it's called literal notation.

00:20.340 --> 00:27.870
So as you know, when we use constructor notation, we write your variable person equals to new object.

00:29.740 --> 00:33.480
Let's run it again in Castle and see how it works.

00:36.900 --> 00:44.790
So we have an object which is represented with curly braces and those Calabrese is exactly what we need

00:44.790 --> 00:46.290
in little notation method.

00:47.430 --> 00:50.400
Let's the this new object and instead of it.

00:50.400 --> 00:50.790
Right.

00:50.790 --> 00:52.140
Just curly braces.

00:54.550 --> 01:01.210
Reload and you see, nothing is changed because we have just created new empty object again, but using

01:01.210 --> 01:06.610
a different way calibrates this is not an operator like DOT or square brackets.

01:06.610 --> 01:14.290
Operator when JavaScript engine is empty color Brice's, it knows that it has to create an object in

01:14.290 --> 01:16.530
order to add properties to person object.

01:16.900 --> 01:26.620
We have just the right property names inside curly braces that column and the value reload.

01:27.880 --> 01:30.160
So we have a first name, John.

01:30.850 --> 01:34.180
If we want to add more properties, we do it in the same way.

01:34.600 --> 01:38.070
But you need to know that we have to separate them by commas.

01:38.800 --> 01:40.330
Let's add other properties.

01:40.600 --> 01:46.690
Last name Smith and age 27.

01:47.840 --> 01:48.370
All right.

01:49.030 --> 01:54.100
For better readability like it was in case of iRace, let's organize our code.

01:54.340 --> 01:55.870
It's more convenient.

01:56.170 --> 02:01.750
Better to read and prefer to wait when we work with objects in case of constructor method to get the

02:01.750 --> 02:08.890
same result we needed to write variable person one equals two new object.

02:11.030 --> 02:21.770
Then for adding each property we needed to right every time person one dot first name equals two bob.

02:23.940 --> 02:33.880
That person won that last name equals the dough, and eventually the result is same.

02:34.860 --> 02:41.040
So you can see how convenient this literal notation method, the code is clearer, it's easy to read

02:41.040 --> 02:42.180
and we type less.

02:43.080 --> 02:50.100
But regardless of that, you're able to add properties and methods using dot our brackets operator in

02:50.100 --> 02:52.180
case of literal notation method as well.

02:52.680 --> 02:55.380
So I recommend to use literal notation.

02:56.370 --> 03:01.850
All right, let's remove this code and now create inside person another object.

03:02.670 --> 03:06.210
We can do it in the exact same way we need to use curly braces.

03:06.600 --> 03:15.120
So right doctor with its properties name as memory and age five.

03:17.390 --> 03:24.550
Reload and again, we have a new object inside person object to access on the values of the properties

03:24.560 --> 03:27.100
is the same as it was in constructor notation method.

03:28.190 --> 03:30.760
So let's get the value from that through object.

03:31.580 --> 03:41.090
Let's duplicate that log in order to avoid typing the same each time and add Dr. Dot name.

03:42.820 --> 03:45.220
Reload and we have merit.

03:46.810 --> 03:53.290
All right, let's talk about functions in object, which are called methods in order to pass the function

03:53.290 --> 03:54.200
inside an object.

03:54.220 --> 04:00.620
At first we have to write method name and we have to do it in the same way as it was for the properties.

04:01.180 --> 04:07.170
So write my function then assigned to it function.

04:08.440 --> 04:13.240
We always use anonymous functions, which is a function without name.

04:13.930 --> 04:18.030
We use anonymous functions here because we can call them using method names.

04:18.790 --> 04:20.310
Let's see it right.

04:20.320 --> 04:21.300
Cancel that log.

04:22.240 --> 04:23.020
Hello World.

04:26.560 --> 04:39.490
And then in order to call this method right person, that my function, because of that, we have consulate

04:39.490 --> 04:40.700
log inside the function.

04:41.050 --> 04:46.260
We do not need to write it again when we call this function, reload the page.

04:46.270 --> 04:47.460
And here we have.

04:47.590 --> 04:48.420
Hello, Walt.

04:49.300 --> 04:49.810
All right.

04:50.260 --> 04:54.660
Let's make our example more complex and use the properties inside the function.

04:55.270 --> 04:58.720
But before that, let's pass some parameters to you.

04:59.320 --> 05:05.320
For example, daughter name than father name.

05:07.820 --> 05:10.060
And Dr. H

05:14.540 --> 05:19.340
and then writing Castle, not a name plus.

05:20.960 --> 05:31.730
Is a daughter of that place, your second parameter father's name, then again, some text, and she

05:31.730 --> 05:32.090
is.

05:34.000 --> 05:40.660
Then we need to your daughter age and finally years old.

05:43.340 --> 05:50.240
All right, now past the arguments here and use the properties of person object as daughter name, we

05:50.240 --> 05:51.130
should right here.

05:51.140 --> 05:55.760
Person, dot, dot, dot name.

05:58.530 --> 06:07.770
Then as the father name right person, that first name and as for the age of daughter, that's right,

06:07.770 --> 06:11.780
person, dot, dot, dot, h

06:14.310 --> 06:14.900
reload.

06:15.960 --> 06:21.090
And we have Mary is a daughter of John, and she is five years old.

06:22.490 --> 06:27.330
All right, we can pass new object as the arguments on the fly.

06:28.400 --> 06:34.490
I mean, when we call the function for that, we need only one parameter because we are going to use

06:34.490 --> 06:36.230
object as an argument.

06:36.710 --> 06:39.500
Let's place here as a parameter part.

06:41.710 --> 06:47.290
Then create an object on the fly, right?

06:47.380 --> 06:48.190
That's her name.

06:50.930 --> 06:55.100
As Jesse then father name.

06:57.590 --> 06:58.190
Michael.

07:00.050 --> 07:02.480
And as Dr. H.

07:02.480 --> 07:09.920
Writes, you fight, as we already know, to get the values of the properties from the objects we need

07:09.920 --> 07:11.470
to use dot operator.

07:12.020 --> 07:16.850
So write to all the properties per dot.

07:18.590 --> 07:24.950
So, again, we have passed a single parameter inside our method, then we passed on the fly and object

07:24.950 --> 07:30.200
as an argument and used its property values revoked.

07:31.790 --> 07:36.380
And we have Jesse is a daughter of Michael and she's five years old.

07:37.340 --> 07:37.870
All right.

07:38.570 --> 07:44.290
You already know much about objects, but because of that, JavaScript is an object based language.

07:44.780 --> 07:50.150
We need to go deeper and learn advanced things regarding objects, and you will do it throughout the

07:50.150 --> 07:50.500
course.

07:51.080 --> 07:53.900
But for now, for the basic level, it's really excellent.

07:55.070 --> 07:55.790
Let's go ahead.
