1
00:00:00,876 --> 00:00:03,519
Let's now talk about object data types and

2
00:00:03,519 --> 00:00:07,595
the constructor property. All object data

3
00:00:07,595 --> 00:00:10,097
types inherit from Object, not the

4
00:00:10,097 --> 00:00:12,654
primitives though, just the objects. So

5
00:00:12,654 --> 00:00:15,413
Object has a constructor property, and

6
00:00:15,413 --> 00:00:17,604
this constructor property returns a

7
00:00:17,604 --> 00:00:20,802
reference to the object itself. It's from

8
00:00:20,802 --> 00:00:23,351
this that we can find out a few things

9
00:00:23,351 --> 00:00:26,233
about this object. So if we were to look

10
00:00:26,233 --> 00:00:28,271
at this little screenshot here, you can

11
00:00:28,271 --> 00:00:31,918
see I've got _products = function Array,

12
00:00:31,918 --> 00:00:35,107
product = function Object. These are the

13
00:00:35,107 --> 00:00:37,494
constructor properties displayed in the

14
00:00:37,494 --> 00:00:38,739
console.log. This is what we're going to

15
00:00:38,739 --> 00:00:40,930
see in just a minute in our demo. Object

16
00:00:40,930 --> 00:00:43,783
literals and primitives are cast to

17
00:00:43,783 --> 00:00:46,293
objects for display, so if we actually

18
00:00:46,293 --> 00:00:48,293
say, hey, let's do this in a console.log

19
00:00:48,293 --> 00:00:50,678
and take a primitive and apply the

20
00:00:50,678 --> 00:00:53,864
constructor property to it, it casts it to

21
00:00:53,864 --> 00:00:57,205
an object data type first. Then it can

22
00:00:57,205 --> 00:00:59,749
apply the constructor property. So let's

23
00:00:59,749 --> 00:01:01,776
take a look at a demo of using our

24
00:01:01,776 --> 00:01:06,258
constructor property with various data

25
00:01:06,258 --> 00:01:09,007
types. In this constructor sample, again,

26
00:01:09,007 --> 00:01:12,526
I'm defining some various values here, and

27
00:01:12,526 --> 00:01:14,696
then we're going to go and look at the

28
00:01:14,696 --> 00:01:17,259
constructor property. But I want to run

29
00:01:17,259 --> 00:01:20,505
this for you first so we can take a look

30
00:01:20,505 --> 00:01:24,576
at it here. So this is what we get. We get

31
00:01:24,576 --> 00:01:28,106
_products = function Array, and then some

32
00:01:28,106 --> 00:01:30,094
curly braces, and then some native code.

33
00:01:30,094 --> 00:01:32,292
So what the constructor property does is,

34
00:01:32,292 --> 00:01:35,317
it's kind of an internal representation of

35
00:01:35,317 --> 00:01:37,991
this particular object. So an array looks

36
00:01:37,991 --> 00:01:41,042
like this, product = function Object.

37
00:01:41,042 --> 00:01:44,054
Product.productID is function Number. Now

38
00:01:44,054 --> 00:01:45,770
remember, these are primitives, productID

39
00:01:45,770 --> 00:01:48,715
and productNumber. So what it does is, it

40
00:01:48,715 --> 00:01:50,903
casts those primitives to the appropriate

41
00:01:50,903 --> 00:01:53,833
object like number or string. Now

42
00:01:53,833 --> 00:01:56,191
introDate was defined as a new Date, so

43
00:01:56,191 --> 00:01:59,224
that is an object, comes back as function

44
00:01:59,224 --> 00:02:02,023
Date. StrValue is defined as new String,

45
00:02:02,023 --> 00:02:04,061
so it comes back as function String. So

46
00:02:04,061 --> 00:02:07,140
you get the idea here. So this constructor

47
00:02:07,140 --> 00:02:09,322
property, when you apply the toString, it

48
00:02:09,322 --> 00:02:11,280
just simply returns a string that tells

49
00:02:11,280 --> 00:02:15,208
you what data type it is. Pretty simple.

50
00:02:15,208 --> 00:02:17,169
If we look back here at the code, you can

51
00:02:17,169 --> 00:02:20,512
see what that looks like. _products on

52
00:02:20,512 --> 00:02:25,327
line 49, .constructor .toString. On line

53
00:02:25,327 --> 00:02:28,664
50, product.constructor .toString. Now,

54
00:02:28,664 --> 00:02:31,464
product.productID .constructor, productID

55
00:02:31,464 --> 00:02:34,838
is a primitive, but it casts it to the

56
00:02:34,838 --> 00:02:37,089
object and then gives it the property

57
00:02:37,089 --> 00:02:39,958
constructor so that we can then report

58
00:02:39,958 --> 00:02:46,000
that back. And all we get back is a string that we can then output. Very simple.

