text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
So-- the way to get the keys of
an object, is this function called | 2,626.11 | 6.65 |
object.keys | 2,632.76 | 1.11 |
[TYPING] | 2,633.87 | 3.318 |
So, so by doing object.keys
and passing in the object, | 2,641.46 | 3.39 |
we now have an array full of the string
values of the keys in that object. | 2,644.85 | 5.68 |
And so what we're going to do is, we're
going to iterate through those keys. | 2,650.53 | 3.39 |
Check to see if the
value is of an object. | 2,653.92 | 3.29 |
If so, we'll go ahead and clone that. | 2,657.21 | 2.01 |
Let's not worry about functions, or
any of those other things for now. | 2,659.22 | 3.96 |
Otherwise, just return that value. | 2,663.18 | 3.61 |
So, let's have this for loop-- | 2,666.79 | 1.25 |
[TYPING] | 2,668.04 | 3.479 |
And do that. | 2,680.47 | 0.52 |
So first, let's define-- | 2,680.99 | 1.49 |
[TYPING] | 2,682.48 | 3.246 |
The new objects that
we're going to return. | 2,689.449 | 1.791 |
And let's just start with
an empty object for now. | 2,691.24 | 4.18 |
And so, now we have to check to see
if each of these values is an object. | 2,695.42 | 4.07 |
If so, copy it, otherwise return. | 2,699.49 | 2.11 |
So how are we going to check
the type of a particular key? | 2,701.6 | 5.345 |
AUDIENCE: Type of operator. | 2,706.945 | 1.125 |
JORDAN: Yeah, exactly,
that type of operator. | 2,708.07 | 1.875 |
So we can do if the type of
obj, and then pass in by keys. | 2,709.945 | 6.877 |
[TYPING] | 2,716.822 | 2.892 |
So what do we want to check against? | 2,724.331 | 1.499 |
[TYPING] | 2,725.83 | 3.199 |
All right, what am I doing wrong here? | 2,730.4 | 2.122 |
AUDIENCE: Three equals. | 2,732.522 | 1.608 |
JORDAN: Yeah, we should always
use that three equal signs. | 2,734.13 | 1.53 |
In this case it would matter. | 2,735.66 | 1.208 |
But, we should just get in
the habit of doing that. | 2,736.868 | 2.512 |
I mean so if you notice here, we
actually have bracket notation | 2,739.38 | 3.09 |
within bracket notation. | 2,742.47 | 1.08 |
That is totally fine. | 2,743.55 | 2.361 |
Cool. | 2,745.911 | 0.499 |
So, if something is an object
to what are we going to turn? | 2,746.41 | 3.5 |
We can do object, new
object with that key. | 2,749.91 | 6.59 |
[TYPING] | 2,756.5 | 3.458 |
Equals-- what? | 2,766.39 | 1.48 |
AUDIENCE: The value? | 2,774.11 | 1.44 |
Oh no, I'm sorry, deep copy. | 2,775.55 | 1.45 |
JORDAN: Yeah, let's actually
deep copy that value to two. | 2,777 | 2.374 |
[TYPING] | 2,779.374 | 3.206 |
Otherwise-- | 2,787.421 | 0.499 |
[TYPING] | 2,787.92 | 3.19 |
We can just set it
equal to the other key. | 2,793.01 | 2.472 |
[TYPING] | 2,795.482 | 3.297 |
And then at the very end, we
can just return that new object. | 2,801.61 | 3.44 |
[TYPING] | 2,805.05 | 3.283 |
Cool. | 2,812.56 | 1.66 |
Anybody see any bugs? | 2,814.22 | 2.29 |
Candy opportunity. | 2,816.51 | 2.516 |
All right, let's just
go ahead and test this. | 2,819.026 | 3.714 |
So-- let's do-- | 2,822.74 | 4.26 |
Do copy o-- | 2,833.776 | 0.934 |
Then update o-- | 2,838.646 | 2.46 |
[TYPING] | 2,841.106 | 3.444 |
o.obj.key Let's say of to new key. | 2,846.03 | 4.36 |
[TYPING] | 2,850.39 | 3.43 |
o3.obj.key. | 2,856.76 | 0.98 |
Get rid of that. | 2,863.82 | 0.75 |
All right, so moment of truth-- | 2,868.38 | 2.163 |
[TYPING] | 2,870.543 | 3.247 |
Key, rather than new key. | 2,873.79 | 1.06 |
So we did it. | 2,874.85 | 2.675 |
Whew. | 2,877.525 | 1.875 |
All right, any other questions about-- | 2,879.4 | 1.86 |
objects, mutating,
references, any of that stuff? | 2,883.9 | 2.97 |
No, great. | 2,890.55 | 1.03 |
So, arrays as well, are
also stored by reference. | 2,891.58 | 4.3 |
So if we were to do
the same exact example, | 2,895.88 | 2.01 |
and rather than updating the
object, we updated that array, | 2,897.89 | 4.054 |
we'd end up with the same exact results. | 2,901.944 | 1.666 |
And so, if we were to update our
deep copy function to also take | 2,903.61 | 5.58 |
care of arrays, all we have to
do is also check, rather than | 2,909.19 | 3.761 |
checking object, also check against
arrays or any other data types | 2,912.951 | 2.749 |
that we're going to check. | 2,915.7 | 1.083 |
Let's move on to prototype inheritance. | 2,920.5 | 3.57 |
So what exactly is
prototype inheritance? | 2,924.07 | 1.96 |
Well, so non-primitive types
have a few properties and methods | 2,926.03 | 3.26 |
associated with them. | 2,929.29 | 1.68 |
So, array, we have this
thing called array.push, | 2,930.97 | 2.58 |
which will add values to an array. | 2,933.55 | 1.54 |
So, say we have something like-- | 2,935.09 | 2.076 |
[TYPING] | 2,937.166 | 2.294 |
An empty array, if we did array.push-- | 2,939.46 | 2.73 |
some value, then array
now has something in it. | 2,942.19 | 5.631 |
If we were to push
another value into it-- | 2,947.821 | 1.749 |
It now has two values in it. | 2,952.435 | 1.315 |
So array.prototype.push
is a method that we | 2,953.75 | 3.77 |
have available on all arrays, that
just adds new values to an array. | 2,957.52 | 4.96 |
Another one would be like,
string.prototype.toUpperCase. | 2,962.48 | 3.175 |
So, say we were to
have some string, so-- | 2,965.655 | 2.545 |
[TYPING] | 2,968.2 | 2.591 |
If you do str.toUpperCase-- | 2,971.29 | 3.86 |
Now we, we're left with a new
string with all uppercase. | 2,975.15 | 3.45 |
So, these are just functions that we
can invoke on any non-primitive that | 2,978.6 | 4.31 |
gives us something else. | 2,982.91 | 2.64 |
That is available to all
non-primitives of a given type. | 2,985.55 | 5.13 |
So each object stores a
reference to its prototype. | 2,990.68 | 2.49 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.