1
00:00:00,360 --> 00:00:05,490
Hello welcome to the section on object oriented programming here's what we'll be doing in this section

2
00:00:05,490 --> 00:00:05,950
.

3
00:00:06,150 --> 00:00:12,000
We're going to define what object oriented programming or O.P. is and revisit the new keyword and understand

4
00:00:12,000 --> 00:00:13,630
it in quite a bit of depth.

5
00:00:13,860 --> 00:00:18,990
We'll then use constructor functions to reduce code duplication and refactor our constructors using

6
00:00:18,990 --> 00:00:20,100
call and apply.

7
00:00:20,400 --> 00:00:25,450
If you haven't watched a series on the keyword this I highly recommend that you do that first.

8
00:00:25,590 --> 00:00:30,840
Everything in these videos will build all of our knowledge of the key word this as well as call apply

9
00:00:30,990 --> 00:00:31,920
and bind.

10
00:00:31,920 --> 00:00:32,800
Here we go.

11
00:00:33,330 --> 00:00:35,450
So what is object oriented programming.

12
00:00:35,460 --> 00:00:41,970
Simply put it's a programming model based around the idea of objects and blueprints which create objects

13
00:00:42,480 --> 00:00:47,580
we call these blueprints classes and the objects that we create from our classes are traditionally called

14
00:00:47,670 --> 00:00:50,650
instances in object oriented programming.

15
00:00:50,790 --> 00:00:56,220
We strive to make our classes abstract and modular so that we can reuse classes easily and share them

16
00:00:56,220 --> 00:00:58,680
amongst all parts of an application.

17
00:00:58,710 --> 00:01:04,140
Javascript does not have built in support for classes unlike languages like Python Ruby and Java.

18
00:01:04,370 --> 00:01:10,980
We can mimic the behavior of classes by using Javascript has functions and objects before we see how

19
00:01:10,980 --> 00:01:13,910
to use functions to mimic the behavior of water classes.

20
00:01:14,040 --> 00:01:17,610
Let's see why this programming technique is quite useful.

21
00:01:17,610 --> 00:01:22,040
Imagine for a second that you're an architect and you're tasked with building 4 houses.

22
00:01:22,230 --> 00:01:27,440
Each house is going to have a number of bedrooms bathrooms as well as a number of square feet.

23
00:01:27,450 --> 00:01:30,690
The first thing that might come to mind is let's make an object for each house.

24
00:01:30,690 --> 00:01:32,010
We need to make.

25
00:01:32,190 --> 00:01:37,710
Seems pretty reasonable but once we start having to create more than a few objects things get very repetitive

26
00:01:37,830 --> 00:01:38,940
and tedious.

27
00:01:39,510 --> 00:01:43,830
Let's refactor this code by reading a blueprint for what a house should look like.

28
00:01:44,100 --> 00:01:49,380
Let's make a function that when used we'll construct a house object in javascript.

29
00:01:49,380 --> 00:01:52,650
We call the special functions constructor functions.

30
00:01:52,650 --> 00:01:56,100
Now let's see what our constructor function for a house looks like.

31
00:01:56,340 --> 00:01:59,790
Right off the bat we see that the name of the function is capitalized.

32
00:01:59,790 --> 00:02:01,950
This doesn't change anything about the function.

33
00:02:02,040 --> 00:02:06,960
It's just best practice and convention so that other developers know that this is a constructor function

34
00:02:06,960 --> 00:02:07,900
.

35
00:02:07,920 --> 00:02:11,250
The next thing we see is that the keyword this is back.

36
00:02:11,250 --> 00:02:12,900
Just when you thought you were done with it.

37
00:02:13,050 --> 00:02:15,680
If you haven't wants that series please go back and do so.

38
00:02:15,840 --> 00:02:20,110
Otherwise the rest of the series will be quite confusing in this function.

39
00:02:20,110 --> 00:02:25,170
We're attaching properties onto the keyword this we're somehow hoping that when we call the function

40
00:02:25,410 --> 00:02:30,170
a new object will be returned to us with the values specified in this function.

41
00:02:30,190 --> 00:02:32,070
However something's missing here.

42
00:02:32,070 --> 00:02:37,140
If we look at the first house variable we are setting it equal to the result of the house function being

43
00:02:37,140 --> 00:02:38,070
called.

44
00:02:38,070 --> 00:02:41,460
The problem is our house function is not returning anything.

45
00:02:41,550 --> 00:02:43,840
Therefore the function will return undefined.

46
00:02:44,130 --> 00:02:45,690
So how do we fix this issue.

47
00:02:45,690 --> 00:02:49,710
The answer lies in another special keyword that will explore in the next video.

48
00:02:49,770 --> 00:02:50,820
The new keyword.

49
00:02:50,880 --> 00:02:51,650
See you there.
