Transcript from the "hasOwnProperty Method" Lesson
[00:00:27] So, when we don't find a function on the given object, don't panic, head on up. Okay, now, I wanna do something interesting here, no bonus. What if I want to confirm, nothing's changed by the way, except for now I'm not using increment. I'm using this method, this function hasOwnProperty.
[00:00:46] What if we wanna confirm our user1 has the property score? This is interesting, hasOwnProperty here. I presume hasOwnProperty is on user1 as a property, Matt, is it?
>> Speaker 2: Yes, I mean, there's nothing there for it.
>> Will Sentance: There's no property, sorry, no method called hasOwnProperty, yeah, exactly. It must be on user function store, is it Todd?
>> Speaker 2: No, it's not.
[00:01:32] We're gonna learn more about that a little bit later, there it is. I should do it in a different color, honestly. But I'm gonna, instead just kind of, and it has a bunch of useful functions that are gonna be available to, dear. They're gonna be available to all of our objects.
>> Speaker 2: The object
>> Will Sentance: To this object.prototype object. I'm not gonna probably draw the arrow, am I? But let's just do a little star. This user function stores is gonna link down to this object. The object.prototype object, and what do you bet's in there, Matt? What function do you bet's in there?
>> Speaker 2: hasOwnProperty.
>> Will Sentance: hasOwnProperty, he's spot on, hasOwnProperty, super useful I guess. Such that, when I run user1.hasOwnProperty, and execute it with score as my argument. Kayla, where do I look for user 1?
>> Speaker 3: In global.
>> Will Sentance: In global will I find it? Yeah. Then I look for hasOwnProperty on that object.
[00:03:16] Do I find it on user 1?
>> Speaker 3: No.
>> Speaker 3: The user function-
>> Will Sentance: Fantastic, maybe hasOwnProperty's here. Is increment, is No. Do we panic?
[00:03:34] No, here do we go look, what hidden property that we're gonna look at, Kayla?
>> Speaker 3: The prototype.
>> Will Sentance: The proto property, yeah, yeah. Don't worry, we'll see the difference, but the proto property, which is a link to-
>> Speaker 3: Object.proto.
>> Will Sentance: And what do we find there?
>> Speaker 3: hasOwn.
>> Will Sentance: hasOwnProperty, and we grab its code, and we execute it. What we're actually doing with our object.create is kinda taking control of what we put in that proto. Because all objects by default, their proto, as soon as they're created gets a link to object.prototype. We'd have taken control of that, but don't panic, we don't lose access to this stuff down here, because it is a chain all the way up.
[00:04:19] To the point that I kinda want to show the line, just so you know it's a chain, right? It's a chain,
>> Will Sentance: It's a chain all the way up to our headline, Object.prototype. This object also has a proto property. No, but don't panic. Anyone take a guess given this is, I'm just gonna tell you the top of the chain.
[00:04:40] What this might have as its value for proto? Dan?
>> Speaker 2: Under naturalised.
>> Will Sentance: Yeah, actually very close but null, yeah, it's like we're done now, there's no further up the chain, okay? But I'm not going to go into this in greater detail than that, but if you do wanna know all the intricacies of that, go watch the object oriented hard parts.
[00:05:01] Really [LAUGH] or people's talks on that, go parts on that, we go into in much more detail. Especially related to how arrays and functions also had a big collection of shared functions they can use related to this. Okay, there is another thing I want to talk about though.
[00:05:20] Yes, what if you wanna confirm our user's has the property score? We can use the hasOwnProperty method. But where is it? Is it on user 1? No. All of us have a proto property by default which defaults a lead to a big object, object.prototype, full of somewhat, useful functions.
[00:05:34] We can access it via user function store's proto property, the chain goes up.