text
stringlengths 1
81
| start
float64 0
10.1k
| duration
float64 0
24.9
|
|---|---|---|
[MUSIC PLAYING]
| 0
| 2.958
|
JORDAN HAYASHI: Hello, and
welcome for Lecture Two--
| 17.27
| 2.37
|
React, Props, and State.
| 19.64
| 2.4
|
So last week, we talked about a bunch
of different topics, one being ES6
| 22.04
| 3.72
|
and beyond and the syntax
that comes with each of those.
| 25.76
| 2.69
|
We talked about closures,
the process by which
| 28.45
| 2.62
|
a function can reference variables
declared in a parent function.
| 31.07
| 5.13
|
We talked about IIFEs, Immediately
Invoked Function Expressions.
| 36.2
| 3.68
|
We talked about using functions
as first-class citizens.
| 39.88
| 3.675
|
We talked about the execution
stack and event loop,
| 43.555
| 2.125
|
and how JavaScript actually
executes in browsers.
| 45.68
| 2.82
|
We talked about callbacks, promises, and
async/await, all of the different ways
| 48.5
| 3.3
|
to handle asynchronous actions.
| 51.8
| 1.89
|
And last, we talked about this
and the way that this is bound.
| 53.69
| 3.96
|
This week, we're going to
start with classes, which
| 57.65
| 3.23
|
is a syntax I was introduced in ES6.
| 60.88
| 3.639
|
It simplifies the defining of complex
objects that have their own prototypes.
| 64.519
| 4.967
|
And with that, you have
two different things.
| 69.486
| 1.874
|
You have classes and instances.
| 71.36
| 1.53
|
Classes is basically an abstract
thing that you can declare,
| 72.89
| 3.73
|
basically saying, hey, by
the way, any of these objects
| 76.62
| 2.78
|
that you create will have these
methods associated with them.
| 79.4
| 3.03
|
Or they might have these things
attached to them that you can use.
| 82.43
| 4.14
|
And then when you actually
turn an abstract class
| 86.57
| 2.64
|
into an instance of that object,
that is called an instance.
| 89.21
| 4.42
|
An example of that would be the
difference between the date,
| 93.63
| 6.12
|
which is a function-- it's a class--
| 99.75
| 2.66
|
or a new date.
| 102.41
| 1.23
|
So if you do something like
const d equals new date,
| 103.64
| 4.54
|
then now you have a date object itself.
| 108.18
| 3.38
|
And so Date with a capital D
would be a class in that case,
| 111.56
| 3.137
|
and the lowercase D
would be an instance.
| 114.697
| 1.708
|
These instances have things attached
to them, like methods and properties,
| 120.61
| 3.54
|
and the classes have
things like static methods.
| 124.15
| 2.4
|
And so methods are
basically anything that's
| 126.55
| 2.07
|
a function that can be invoked
on any of the instances.
| 128.62
| 4.12
|
You can think of that as a
function on the classes prototype.
| 132.74
| 6.24
|
A static method, on the
other hand, is basically
| 138.98
| 2.6
|
a method that doesn't really care about
the particular instance of a class.
| 141.58
| 3.3
|
Instead, it cares about all instances of
the class, so something like Date.now,
| 144.88
| 10.14
|
where you don't really care about
a specific instance of a date
| 155.02
| 3.78
|
if you just want to get the time.
| 158.8
| 1.92
|
Whereas something like
turning a date to a string--
| 160.72
| 2.62
|
in this class, d.toString--
| 163.34
| 3.625
|
in that case, you do care
about the particular date
| 166.965
| 2.125
|
object that you're working on.
| 169.09
| 1.47
|
And so when you do
capital Date.now, that's
| 170.56
| 2.91
|
considered a static method,
since it's attached to the class.
| 173.47
| 2.97
|
And if you do something like date--
| 176.44
| 2.52
|
lowercase d-- dot toString, that really
matters which instance you're attached
| 178.96
| 4.38
|
to, and therefore, that's a method.
| 183.34
| 2.71
|
Lastly, we have properties,
which are like methods.
| 186.05
| 3.86
|
But rather than being functions,
they're actually just values,
| 189.91
| 3.68
|
and they are associated with a
particular instance of a class.
| 193.59
| 4.55
|
And so with classes come
a few different keywords.
| 198.14
| 2.27
|
We have new, which you saw me type
over here, which is basically saying,
| 200.41
| 3.91
|
hey, give me an instance
of this particular class.
| 204.32
| 2.99
|
You invoke the class like an object, in
case you want to pass anything into it.
| 207.31
| 3.32
|
And so say we want to do new
const d2 equals new date,
| 210.63
| 5.362
|
and we actually want
to pass in some number.
| 215.992
| 1.833
|
That gives us a new date
from a very long time ago.
| 220.69
| 3.93
|
So d.toString.
| 224.62
| 1.29
|
Oh, d2.toString.
| 228.784
| 1.596
|
Since we passed in the number 1,
2, 3, 4, that's basically saying,
| 233.8
| 3.78
|
give me a date that's 1,234 milliseconds
after date 0, which is back in 1969.
| 237.58
| 13.23
|
So a constructor is
basically something that you
| 250.81
| 2
|
define within a class that says,
hey, when you create a new class,
| 252.81
| 3.719
|
invoke this method such that you
create a new instance of a class.
| 256.529
| 5.911
|
So let's actually practice
this a little bit.
| 262.44
| 2.46
|
So is everybody here familiar with
a data structure called a set?
| 264.9
| 3.075
|
So basically what a
set is, is it's a list,
| 273.85
| 3.12
|
a data structure that supports things
like add, delete, and inclusion,
| 276.97
| 4.5
|
where you cannot have multiple
things of the same value.
| 281.47
| 3.62
|
Or in other words, it's
a list of unique values.
| 285.09
| 2.84
|
And the methods that
it should support are
| 287.93
| 2.51
|
add, which is basically
add to this list;
| 290.44
| 2.46
|
delete, which is basically get
rid of something from this;
| 292.9
| 3.06
|
or inclusion, which is saying, hey,
does this list have a particular value?
| 295.96
| 5.97
|
And it should also have the
ability to get its size.
| 301.93
| 2.54
|
And so down at the bottom of
the file, I defined a few tests
| 304.47
| 4
|
that we're going to run after we
implement this, such as line 7 here,
| 308.47
| 4.65
|
we have const s gets a new
set with an array from 1 to 5,
| 313.12
| 4.17
|
which is basically saying, give me a
new set with five values, 1, 2, 3, 4,
| 317.29
| 3.21
|
and 5.
| 320.5
| 1.09
|
We're going to try to
do S.add1, and so we're
| 321.59
| 2.21
|
going to try to add 1
three times to the set.
| 323.8
| 3.37
|
And when we do S.size, we want it
actually to only have five members,
| 327.17
| 4.31
|
because you shouldn't be
able to add 1 multiple times.
| 331.48
| 4.17
|
Down here, we do S.add6,
and then we try S.has6,
| 335.65
| 5.07
|
and it should contain the number 6.
| 340.72
| 2.67
|
That thing should not be there.
| 343.39
| 3.18
|
We try to see the size of it, and
it should have added another member.
| 346.57
| 3.752
|
And then down here, we tried
to delete that and do a couple
| 350.322
| 2.458
|
of associated checks with that.
| 352.78
| 1.85
|
And so how are we going to go
about implementing this class?
| 354.63
| 3.22
|
So as per the slide over here, we
use a method called constructor
| 361.22
| 3.8
|
in order to go ahead and construct
an instance of this class.
| 365.02
| 4.18
|
And so within the class, we should
have a method called constructor,
| 369.2
| 6.31
|
which takes a single argument.
| 375.51
| 3.55
|
It should take an array or some
sort of list to be created with.
| 379.06
| 4.324
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.