text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
Meaning, it has all the-- it
knows about all of these methods. | 2,993.17 | 4.38 |
And it stores a reference to the object
in order to know where these methods-- | 2,997.55 | 6.51 |
the code to actually the run that lies. | 3,004.06 | 4.41 |
And say we have a
prototype chain where there | 3,008.47 | 3.78 |
are a bunch of different
methods of the same name. | 3,012.25 | 2.46 |
Whichever one is bound most tightly
to the instance has the priority. | 3,014.71 | 4.3 |
So say we have an object in
an array, where array is the-- | 3,019.01 | 9.68 |
So say we have a value that is of
type array, up the prototype chain | 3,028.69 | 3.3 |
we have arrays, its prototype is
array, that prototype is object. | 3,031.99 | 4.96 |
Say we have the same named
method on both of these. | 3,036.95 | 2.717 |
If we call that method, the one
that's bound most tightly the, | 3,039.667 | 2.583 |
array will take priority. | 3,042.25 | 2.08 |
So let's actually show that. | 3,044.33 | 1.25 |
So, say we have something like-- | 3,045.58 | 2.64 |
So array, it has a
reference to its prototypes. | 3,052.69 | 4 |
So if you did array dot, double
underscore, proto, double underscore, | 3,056.69 | 5.3 |
we see this large object with
a bunch of different functions. | 3,061.99 | 6 |
And so we see down here, push, which
is that one that we invoked earlier. | 3,067.99 | 7.45 |
So this is exactly how it knows
where that push implementation is. | 3,075.44 | 4.13 |
And so we can do
arr.__proto__.__proto__, | 3,079.57 | 5.68 |
and go even farther up the chain. | 3,085.25 | 2.15 |
So this one has a bunch of other
ones toString value of, whatever. | 3,087.4 | 4.66 |
And if you notice, both the arrays
prototype, and it's arrays prototypes | 3,092.06 | 6.14 |
prototype, have this
method called toString. | 3,098.2 | 4.32 |
And if I were to invoke
arr.toString which one of these | 3,102.52 | 5.22 |
is going to actually get called? | 3,107.74 | 1.47 |
AUDIENCE: The second one. | 3,113.575 | 1.287 |
JORDAN: The second one? | 3,114.862 | 0.958 |
Which one is the second one? | 3,115.82 | 0.96 |
AUDIENCE: Dot proto, dot proto. | 3,116.78 | 1.291 |
[INAUDIBLE] | 3,118.071 | 0.631 |
JORDAN: Dot proto, dot proto. | 3,118.702 | 1.208 |
So, actually the opposite. | 3,119.91 | 2.17 |
So, since the toString,
on the array prototype, | 3,122.08 | 5.98 |
is more specific than the toSting
method on the object prototype, | 3,128.06 | 4.14 |
this one is going to get invoked. | 3,132.2 | 3.21 |
Because its, just because
its more specific. | 3,135.41 | 2.49 |
Because an array is an
array and its an object. | 3,137.9 | 3.666 |
But its more specific to call it an
array, than to call it an object. | 3,141.566 | 2.874 |
So its going to invoke
the one on the array. | 3,144.44 | 2.754 |
Does that makes sense? | 3,147.194 | 0.916 |
Anybody have a question about that? | 3,150.392 | 1.458 |
It's an important concept, and
a little bit confusing at first. | 3,151.85 | 3.46 |
Cool. | 3,160.4 | 0.5 |
Most primitive types
had object wrappers. | 3,160.9 | 2.91 |
And so we talked about
how primitive types don't | 3,163.81 | 3.24 |
have any methods associated with them. | 3,167.05 | 4.46 |
But primitive types
also have wrappers that | 3,171.51 | 2.44 |
have prototypes associated with them. | 3,173.95 | 3.78 |
What the heck does that mean? | 3,177.73 | 1.27 |
So if I were to do
42.toString, It's going | 3,179 | 3.189 |
to be like what the heck do you mean? | 3,182.189 | 1.541 |
42.toString-- | 3,183.73 | 0.541 |
[TYPING] | 3,184.271 | 2.309 |
Right I told you that these
primitive values don't have methods. | 3,186.58 | 5.85 |
And so 42.toString
doesn't really make sense. | 3,192.43 | 3.25 |
But say I were to do this thing
const num = 42 and did num.toString, | 3,195.68 | 5.33 |
[TYPING] | 3,201.01 | 1.05 |
That will actually do something. | 3,202.06 | 1.407 |
And that's a little bit strange. | 3,203.467 | 1.333 |
This is another one of those
JavaScript interesting behaviors. | 3,204.8 | 4.67 |
Because all of the primitive
values have wrappers | 3,209.47 | 3.45 |
that give them access
to a bunch of methods. | 3,212.92 | 3.69 |
And JavaScript will automatically
do what's called boxing for you. | 3,216.61 | 3.98 |
Which it says, hey, like
I know 42 is a primitive, | 3,220.59 | 3.222 |
but if you call this toString
method, I know what you mean. | 3,223.812 | 2.458 |
I'm going to box this 42
number with this prototype that | 3,226.27 | 3.93 |
has a bunch of these methods on it. | 3,230.2 | 2.272 |
So if I were to do 42.toString
that would make sense. | 3,232.472 | 2.208 |
And if I num.__proto__, | 3,234.68 | 2.81 |
[TYPING] | 3,237.49 | 3.13 |
That actually exists. | 3,240.62 | 1.31 |
But 42.__proto__ | 3,241.93 | 0.75 |
[TYPING] | 3,242.68 | 3.3 |
Does not. | 3,245.98 | 0.878 |
Does that make sense? | 3,246.858 | 1.464 |
Another way to find out if a
value is an instance of some type, | 3,256.14 | 5.23 |
you can do this thing
called x instance of number. | 3,261.37 | 3.054 |
And that would return false. | 3,264.424 | 1.166 |
Because x is actually not
of type capital number, | 3,265.59 | 2.87 |
it's just boxed around that
number object for your reference. | 3,268.46 | 6.906 |
Does that make sense? | 3,275.366 | 0.874 |
Again not something you're going to
use everyday, just something that | 3,279.966 | 2.874 |
is helpful to know in case you
run into the strange corner cases. | 3,282.84 | 2.708 |
Cool. | 3,289.52 | 0.91 |
So why would we use a
reference to the prototype? | 3,290.43 | 3.21 |
And what is the alternative there? | 3,293.64 | 1.74 |
Anybody care to give a shot at that? | 3,295.38 | 1.5 |
So this is going back a little bit too
deep copying versus shallow copying. | 3,306.6 | 3.9 |
AUDIENCE: So, maybe if the
initial object is massive. | 3,310.5 | 3.8 |
And then you just want to do
something, like, after it? | 3,314.3 | 4.28 |
JORDAN: Yeah, so if the initial object
is massive, like, what happens then? | 3,318.58 | 4.13 |
So the alternative is basically
to clone every single-- | 3,322.71 | 3.695 |
to deep copy every single
prototype every single time | 3,326.405 | 2.665 |
you couldn't new value. | 3,329.07 | 1.29 |
Which is, safe, because that
number and all of its methods | 3,330.36 | 5.07 |
are all encapsulated within
that specific variable. | 3,335.43 | 3.69 |
But it's also a little bit
expensive in both performance, | 3,339.12 | 2.64 |
because you have to do that
deep copy every single time. | 3,341.76 | 2.43 |
And also of memory, because the
object starts to get pretty large. | 3,344.19 | 3.16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.