1
00:00:02,432 --> 00:00:03,832
Before we look at the call function, let's

2
00:00:03,832 --> 00:00:06,003
review the different ways in which we can

3
00:00:06,003 --> 00:00:07,887
create a function, and how does that

4
00:00:07,887 --> 00:00:10,432
affect the value of the this object.

5
00:00:10,432 --> 00:00:12,832
Here's a function we have seen in the

6
00:00:12,832 --> 00:00:14,765
previous module. We're simply printing the

7
00:00:14,765 --> 00:00:18,932
string 'Hi' and the value of this to the

8
00:00:18,932 --> 00:00:20,807
console. In the previous module, we

9
00:00:20,807 --> 00:00:22,682
learned that every JavaScript function,

10
00:00:22,682 --> 00:00:25,307
while executing, has a reference to its

11
00:00:25,307 --> 00:00:27,932
current execution context to the this

12
00:00:27,932 --> 00:00:30,765
keyword. So what would be the value of

13
00:00:30,765 --> 00:00:34,099
this here? As expected, it refers to the

14
00:00:34,099 --> 00:00:37,682
global Window object. Now here's another

15
00:00:37,682 --> 00:00:40,146
example. This time, we declare a greeting

16
00:00:40,146 --> 00:00:43,432
variable and assign an empty object to it.

17
00:00:43,432 --> 00:00:45,932
Then we define the property sayHi, whose

18
00:00:45,932 --> 00:00:49,159
value is an anonymous function. Its body

19
00:00:49,159 --> 00:00:52,068
is the same as that of the earlier

20
00:00:52,068 --> 00:00:54,289
function. Now the value of this is no

21
00:00:54,289 --> 00:00:56,876
longer the global Window object, because

22
00:00:56,876 --> 00:00:59,988
the execution context in this function is

23
00:00:59,988 --> 00:01:01,988
different. The value of this now refers to

24
00:01:01,988 --> 00:01:04,832
the object referenced by the greeting

25
00:01:04,832 --> 00:01:07,232
variable. Let's look at yet another way a

26
00:01:07,232 --> 00:01:10,682
function's created in JavaScript. This

27
00:01:10,682 --> 00:01:12,832
time, we are using the new keyword when

28
00:01:12,832 --> 00:01:15,932
invoking the sayHi function. This is also

29
00:01:15,932 --> 00:01:18,732
known as the constructive function. The

30
00:01:18,732 --> 00:01:21,132
value of this here will be an empty

31
00:01:21,132 --> 00:01:23,232
object. Any time you invoke a function

32
00:01:23,232 --> 00:01:24,932
with the new keyword, JavaScript

33
00:01:24,932 --> 00:01:27,932
implicitly creates an empty object within

34
00:01:27,932 --> 00:01:31,000
the function before returning it. So in our example, the variable greeting

