1
00:00:00,940 --> 00:00:03,560
And let's now take a look at what happens

2
00:00:03,560 --> 00:00:09,240
with 'this' within constructor functions.

3
00:00:09,240 --> 00:00:11,520
Here I have a constructor function that's

4
00:00:11,520 --> 00:00:13,990
pretty much the same as the literal object

5
00:00:13,990 --> 00:00:16,780
I created earlier. It's has an ID, a name,

6
00:00:16,780 --> 00:00:19,875
a standardCost, a standard price, and a

7
00:00:19,875 --> 00:00:22,140
grossProfit function. Now notice the use

8
00:00:22,140 --> 00:00:24,850
of 'this' inside of here as well. Well,

9
00:00:24,850 --> 00:00:27,130
just like you'd expect, we're also going

10
00:00:27,130 --> 00:00:28,880
to try calling this with a couple of

11
00:00:28,880 --> 00:00:32,410
different objects. So in our function

12
00:00:32,410 --> 00:00:34,860
constructorFunctions, I'm going to create

13
00:00:34,860 --> 00:00:37,540
two different instances of our constructor

14
00:00:37,540 --> 00:00:39,870
function. The first one I'm assigning to a

15
00:00:39,870 --> 00:00:42,790
variable prod1, and the second one I'm

16
00:00:42,790 --> 00:00:45,880
assigning to prod2. They have different

17
00:00:45,880 --> 00:00:49,010
ID's, different product names, and

18
00:00:49,010 --> 00:00:53,115
different standardCost and listPrice. On

19
00:00:53,115 --> 00:00:57,210
lines 31 and 32, I call the grossProfit

20
00:00:57,210 --> 00:00:59,910
function on each one of those, so

21
00:00:59,910 --> 00:01:03,960
prod1.grossProfit, prod2.grossProfit. As

22
00:01:03,960 --> 00:01:07,130
you'd expect, 'this' reflects whichever

23
00:01:07,130 --> 00:01:09,930
object were working with, so prod1 or

24
00:01:09,930 --> 00:01:13,910
prod2. Let's go ahead and run this and

25
00:01:13,910 --> 00:01:17,150
take a look at what happens. And as you'd

26
00:01:17,150 --> 00:01:19,220
expect, we get the different numbers

27
00:01:19,220 --> 00:01:21,090
because we're referencing the different

28
00:01:21,090 --> 00:01:27,000
objects, and 'this' then takes on the properties of that object.

