1
00:00:02,323 --> 00:00:05,989
as person1 is not a function. Just like

2
00:00:05,989 --> 00:00:09,323
call, every function object also has an

3
00:00:09,323 --> 00:00:11,823
apply method. In the examples we have seen

4
00:00:11,823 --> 00:00:14,423
so far, you can easily replace a call with

5
00:00:14,423 --> 00:00:17,545
an apply method. How does an apply then

6
00:00:17,545 --> 00:00:20,823
differ from a call? While the apply method

7
00:00:20,823 --> 00:00:23,123
syntax looks almost identical to that of a

8
00:00:23,123 --> 00:00:25,948
call, call accepts an argument list, while

9
00:00:25,948 --> 00:00:30,323
apply accepts a single array of arguments.

10
00:00:30,323 --> 00:00:31,723
We have an introduction function that

11
00:00:31,723 --> 00:00:34,123
takes in two parameters and prints out a

12
00:00:34,123 --> 00:00:36,823
message. First, we call the introduction

13
00:00:36,823 --> 00:00:38,989
function with the arguments 'John' and

14
00:00:38,989 --> 00:00:41,545
'student'. Next, we call the same

15
00:00:41,545 --> 00:00:44,323
function, once with apply and then with

16
00:00:44,323 --> 00:00:46,212
the call method. Note that the apply

17
00:00:46,212 --> 00:00:48,323
method takes in an array as the argument,

18
00:00:48,323 --> 00:00:51,878
while the call method takes a list of

19
00:00:51,878 --> 00:00:53,823
arguments. We are not really changing the

20
00:00:53,823 --> 00:00:55,656
function context of this value here, so we

21
00:00:55,656 --> 00:00:59,323
just pass undefined as the first argument.

22
00:00:59,323 --> 00:01:02,707
So how do we decide when to use a call or

23
00:01:02,707 --> 00:01:05,573
an apply? Use the apply method when the

24
00:01:05,573 --> 00:01:07,073
input parameter is already in the form of

25
00:01:07,073 --> 00:01:10,323
an array consisting of similar values.

26
00:01:10,323 --> 00:01:12,037
Otherwise, if you're dealing with multiple

27
00:01:12,037 --> 00:01:13,823
arguments that are not really related to

28
00:01:13,823 --> 00:01:17,523
each other, use the call method. Let's see

29
00:01:17,523 --> 00:01:21,823
this in action. This is our example from

30
00:01:21,823 --> 00:01:23,323
earlier. We define the introduction

31
00:01:23,323 --> 00:01:26,573
function and invoke it in three different

32
00:01:26,573 --> 00:01:29,073
ways. Note that we pass the input in the

33
00:01:29,073 --> 00:01:33,323
form of an array to apply, whereas call

34
00:01:33,323 --> 00:01:33,000
accepts all the input as separate arguments.

