Transcript from the "Objects default __proto__" Lesson
>> Will: What are we doing in our first line of code here, if you can just verbalize that for me so I can then diagram it out and we can make sure we're continuing to refine our technical communication. What do we do in that first line of code there, Suzie?
>> Suzie: We have a cons, obj.
>> Will: Obj, [LAUGH] we can pronounce it obj.
>> Suzie: Or obj.
>> Will: Obj.
>> Suzie: Object.
>> Will: I don't know if that's allowed, but yeah, obj, exactly. And it is?
>> Suzie: An object.
>> Will: An object, fantastic. There it is. Okay, and what properties does it have immediately assigned to it?
>> Suzie: Num.
>> Will: Num.
>> Suzie: Properties.
>> Will: Yeah.
>> Suzie: Value of three.
>> Will: Fantastic, well put, okay, now, let's go and access it. And the very next line Michael, talk me through accessing it.
>> Michael: We are calling obj and-
>> Will: Careful using the word calling for an object, that's for functions.
[00:00:49] So I would guess we are looking up pbj or we're referencing obj or we're, yeah, we're looking at memory for obj and we find it.
>> Michael: Yep, we get the property name, num.
>> Will: Yeah, exactly which is the value?
>> Michael: a 3.
>> Will: 3, right. Easy, or maybe not, or maybe easy.
[00:01:09] It's uses next property. Obj.hasOwnProperty and it's a function that takes in an argument the string num. Let's do the lookup. Michael. Where do we look for obj?
>> Michael: In the memory.
>> Will: In global memory, spot on, yeah. Do we find it?
>> Michael: Yes
>> Will: Yes, where do we look for hasOwnProperty?
[00:01:42] We look for it on on the object right, it's just like num, we're looking for it. We found num, it was there, we looked for hasOwnProperty, is it on there?
>> Michael: I don't see it.
>> Will: It's definitely definitely not but we do look on the object, because it's a property of obj, which we're trying to access.
[00:01:58] Do we find it?
>> Michael: No.
>> Will: No, do we give up?
>> Michael: No.
>> Will: No, where do you think we might go and look? What hidden property?
>> David: [INAUDIBLE]
[00:03:26] It's in memory, but we're not putting there. And one of the first things in there is called object. It is a function, it's actually a function that by the way when called with a new keyword it's gonna return us an object, but we don't need to worry about that for now.
[00:03:44] It's just an object. Is that right? No, it's not, it's a function, but as a function therefore, must also be an object. So it's a function and also an object, okay?
>> Will: There it is, there's the object, there's the object.
>> Will: That object by default as all objects in function object combos have, has what property do we think Chris, what all objects in function object combos have a property by default.
>> Chris: Prototype?
>> Will: Fantastic, thank you Chris, yes, prototype. Which is itself a big old object,
>> Will: A sub-object I guess, and that object has,
>> Will: A function on it, a property on it called has own property. It has a few others like four or five others, one's called, I don't know.
[00:04:44] What are they called? Two local strings, is that a few others on there? There it is, has own property. And this object here is what our underscore proto underscore points to to this object here. The object.prototype. So we'd see in here the word object.prototype. So Seth for me look at process on obj that has on property that jobs will actually follow.
>> Seth: So it's gonna look on obj in government ring. It's not gonna find it there, it's gonna freak out a little, then it's gonna look in the proto, look in the object, look at its prototype, find has own property, and then be happy.
>> Will: Fantastic, excellent, it's gonna call it, and check on obj that num exists, and give us back true.
[00:06:46] Very interesting, okay. So what this means folk is when we in our creation of user 1 get an object that says name fill score for dunder score proto dunder score is usercreator.prototype, go grab those functions there. Well, hold on, do we lose access to hasOwnProperty? No, because that, we're gonna see in a moment, don't worry, that object that has increment and log in on the prototype object itself, is an object.
[00:07:25] So itself has a proto reference, a proto property which leads up to object.prototype. It's a chain of links up and all what we do is we intercede, in that chain. We say, okay, user one, you're dunder proto dunder, is going to refer to Usercreator.prototype which is an object.
[00:07:51] That object has its own dunder proto, so if we don't find has our own property on that object, because we've only got increment and login on there. We head up to the next one object.prototype which is where it's at exactly.