1
00:00:00,210 --> 00:00:01,170
Welcome back.

2
00:00:01,170 --> 00:00:06,090
In this video we'll be talking about the fourth rule for determining what the key word this is and we'll

3
00:00:06,090 --> 00:00:10,810
recap all four rules to help you wrap your mind around this tricky topic.

4
00:00:10,830 --> 00:00:16,140
The fourth rule for determining the value of the keyword this is when you see the new keyword.

5
00:00:16,380 --> 00:00:19,870
The new keyword is a reserve keyword which does quite a few things.

6
00:00:20,010 --> 00:00:24,390
We'll be covering the New keyword in more depth in the object oriented programming section.

7
00:00:24,540 --> 00:00:30,660
But for now just know that when the new keyword is used a new object is created out of thin air.

8
00:00:30,660 --> 00:00:35,130
The new keyword is used with a function and inside of the function definition.

9
00:00:35,130 --> 00:00:39,140
The key word this refers to the new object that is created.

10
00:00:39,150 --> 00:00:45,060
Finally when the new keyword is used an implicit return this is added to the function which uses it

11
00:00:45,060 --> 00:00:46,020
.

12
00:00:46,020 --> 00:00:50,760
That sounds like a lot but will cover it in great detail and the object oriented programming section

13
00:00:50,760 --> 00:00:51,240
.

14
00:00:51,420 --> 00:00:54,060
For now let's take a look at this code example.

15
00:00:54,090 --> 00:00:57,310
We have a function called person which takes in two parameters.

16
00:00:57,390 --> 00:00:59,040
First name and last name.

17
00:00:59,370 --> 00:01:02,490
Inside of this function we're attaching properties on the keyword.

18
00:01:02,490 --> 00:01:05,950
This equal to the values passed to the function.

19
00:01:06,030 --> 00:01:08,970
You may be thinking hold on the value of the keyword.

20
00:01:08,970 --> 00:01:10,540
This is the global object.

21
00:01:10,620 --> 00:01:14,620
We saw that in a previous video and in fact you'd be absolutely right.

22
00:01:14,640 --> 00:01:19,090
However the value of the keyword this changes when we use the new keyword.

23
00:01:19,230 --> 00:01:25,260
Like we said before the keyword this now refers to an object that is created when the new keyword is

24
00:01:25,260 --> 00:01:26,180
used.

25
00:01:26,190 --> 00:01:31,500
We're storing that object in a variable called L-E and can then access the first name and last name

26
00:01:31,500 --> 00:01:33,340
properties on it.

27
00:01:33,360 --> 00:01:38,720
To recap we covered quite a lot in the section we examined the key word this which is a reserve key

28
00:01:38,720 --> 00:01:42,870
word in javascript and its value is determined at execution.

29
00:01:42,870 --> 00:01:47,970
We saw four rules global implicit explicit and the new keyword.

30
00:01:47,970 --> 00:01:53,550
When the keyword this is in the global context or in a function it is either the global object which

31
00:01:53,550 --> 00:01:54,210
is the window.

32
00:01:54,220 --> 00:02:00,300
If in the browser or undefined if we're using strict mode when the keyword this is inside of a declared

33
00:02:00,360 --> 00:02:05,940
object the value of the keyword this will always be the closest parent object.

34
00:02:05,940 --> 00:02:12,510
When we lose the context of the keyword this we can explicitly set the value using call apply or bind

35
00:02:12,530 --> 00:02:12,950
.

36
00:02:13,320 --> 00:02:16,800
Finally when the new key word is used the value of the keyword.

37
00:02:16,800 --> 00:02:23,210
This is set to an empty object and return from the function that is used with the new keyword.

38
00:02:23,220 --> 00:02:27,900
Congratulations you made it through the series on the keyword this pat yourself on the back.

39
00:02:27,900 --> 00:02:29,690
This is some complex material.

40
00:02:29,820 --> 00:02:34,050
If you're still tripped up try to walk through the code examples and be sure to ask us any questions

41
00:02:34,050 --> 00:02:34,140
.

42
00:02:34,140 --> 00:02:35,340
We're always happy to help.

43
00:02:35,490 --> 00:02:36,130
Thanks for watching
