Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,150 --> 00:00:06,750
So in the last video we learned about classes and we learned about properties and methods.
2
00:00:06,770 --> 00:00:14,670
There too. Now next generation javascript also offers a different syntax of initializing properties and methods.
3
00:00:14,830 --> 00:00:19,120
And actually it is this more modern syntax I'll use in this course.
4
00:00:19,160 --> 00:00:21,280
So I want to show it to you here too.
5
00:00:21,530 --> 00:00:27,170
You already learned that properties are like variables you attach to classes and objects, methods are
6
00:00:27,170 --> 00:00:34,070
like functions attached to classes and objects and you'll learn about this syntax where we set up properties
7
00:00:34,070 --> 00:00:35,750
in the constructor function.
8
00:00:35,750 --> 00:00:43,400
Now there is a more modern syntax which spares us using this constructor function with next generation
9
00:00:43,400 --> 00:00:46,380
javascript as we will use it in this course.
10
00:00:46,490 --> 00:00:52,880
You can assign a property directly inside your class with myProperty equals value.
11
00:00:52,880 --> 00:00:55,680
So you skip the constructor function call.
12
00:00:55,850 --> 00:00:59,270
Behind the scenes this will still be transformed to use constructor functions.
13
00:00:59,330 --> 00:01:04,010
But you'll have an easier time writing this and for methods, it's pretty similar.
14
00:01:04,010 --> 00:01:05,140
This is the old way.
15
00:01:05,150 --> 00:01:07,070
I showed you in the last lecture.
16
00:01:07,310 --> 00:01:13,880
Now the next generation javascript way is to use the syntax from the left where you set up a property
17
00:01:14,270 --> 00:01:20,930
and simply think of a method as a property which stores a function as a value and then you end up with
18
00:01:20,930 --> 00:01:21,580
that.
19
00:01:21,770 --> 00:01:26,030
My method equals and then an arrow function.
20
00:01:26,030 --> 00:01:32,950
The great advantage of this syntax is that since you use an arrow function as a property value here you've
21
00:01:32,960 --> 00:01:39,350
got no problems with the this keyword and that's the exact reason why we will use this syntax here on the
22
00:01:39,350 --> 00:01:44,080
bottom right corner and the syntax on the bottom left corner throughout this course.
23
00:01:44,150 --> 00:01:46,240
Let me show you the syntaxes to you.
24
00:01:47,040 --> 00:01:52,330
Back to jsbin on the project we already worked on here with the human and the person class.
25
00:01:52,440 --> 00:01:57,310
We can get rid of the constructor in the human class and get rid of the this keyword.
26
00:01:57,320 --> 00:02:00,890
and just set gender equal to male and print.
27
00:02:00,900 --> 00:02:06,450
Gender can be set equal to an arrow function where we console log.
28
00:02:06,450 --> 00:02:11,430
this.gender still using the this keyword in here when we reach out to the property.
29
00:02:11,440 --> 00:02:17,610
Though you may ignore that arrow for now the same for the person we no longer need the constructor
30
00:02:17,700 --> 00:02:20,860
and we no longer need to call super for that reason.
31
00:02:20,880 --> 00:02:27,750
Instead what we do is we call this name without this just name equal to Max and gender equal female
32
00:02:27,760 --> 00:02:35,840
if you want to and printMyName equals an arrow function too, like this.
33
00:02:35,840 --> 00:02:41,330
Now if you clear this and run this you will get an error because it doesn't recognize the syntax
34
00:02:41,660 --> 00:02:46,600
you actually need to go to the dropdown where it says javascript and choose ES6.
35
00:02:46,700 --> 00:02:47,920
Babel here.
36
00:02:48,260 --> 00:02:52,230
If you do this and hit clear and run you'll see Max and female.
37
00:02:52,250 --> 00:02:55,490
You'll still see the arrows on the left but you may ignore them.
38
00:02:55,490 --> 00:03:01,490
This is the syntax which is next generation javascript which we will actually use in this course.
4181
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.