Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
      You have completed Object-Oriented JavaScript!
      
    
You have completed Object-Oriented JavaScript!
Preview
    
      
  What is an object? Why are objects important? In this video, learn about the "what" and "why" of object-oriented programming.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
                      So what is an object?
                      0:00
                    
                    
                      An object is a neat and
                      0:01
                    
                    
                      tidy package of information about
something you want to use in your code.
                      0:02
                    
                    
                      This package contains
a group of properties and
                      0:07
                    
                    
                      functions that work together to
represent something in your program.
                      0:09
                    
                    
                      As a reminder,
an object's properties are a series of
                      0:14
                    
                    
                      key value pairs that hold
information about the object.
                      0:17
                    
                    
                      And its functions are called methods.
                      0:19
                    
                    
                      Methods let your object do something or
let something be done to it.
                      0:22
                    
                    
                      The term object oriented programming
is really just describing a programming
                      0:26
                    
                    
                      paradigm.
                      0:31
                    
                    
                      Or a way of thinking about in designing
a computer program that uses objects
                      0:32
                    
                    
                      as its core.
                      0:37
                    
                    
                      A lot of developers find it helpful to
think of object's in a code as a way to
                      0:38
                    
                    
                      model real life objects.
                      0:41
                    
                    
                      Real life objects have states and
behaviors and so the JavaScript objects.
                      0:43
                    
                    
                      In JavaScript states are represented
by the object's properties and
                      0:47
                    
                    
                      behaviors are represented
by the object's methods.
                      0:51
                    
                    
                      So if we were helping to
represent a house in our code.
                      0:55
                    
                    
                      We can make a house object with properties
like square footage, color and year built.
                      0:57
                    
                    
                      Or if we wanna to model a radio.
                      1:03
                    
                    
                      We could make a radio object with
properties like station and volume and
                      1:05
                    
                    
                      methods like turn off or change station.
                      1:09
                    
                    
                      Just like these object's states
can be changed in real life,
                      1:13
                    
                    
                      we can paint a house or build an addition.
                      1:17
                    
                    
                      Tune a radio or increase the volume.
                      1:19
                    
                    
                      We can change these states in our code
by updating an object's properties.
                      1:21
                    
                    
                      The idea of mimicking or
                      1:26
                    
                    
                      modelling real life objects is a pretty
good way to try and think about objects,
                      1:27
                    
                    
                      properties and methods when
we're first learning about them.
                      1:31
                    
                    
                      But it's not always super realistic.
                      1:34
                    
                    
                      Sometimes we are trying to model real life
objects like houses or radios in our code.
                      1:37
                    
                    
                      But more often,
our objects are a little more abstract or
                      1:43
                    
                    
                      less analogous to things we
might use in everyday life.
                      1:46
                    
                    
                      Most of the time when we design objects
we're creating an easy way to store
                      1:49
                    
                    
                      information about
something via properties.
                      1:53
                    
                    
                      And access, manipulate or
utilize that information via methods.
                      1:56
                    
                    
                      These objects are more like data
containers than abstractions of real
                      2:00
                    
                    
                      life objects.
                      2:05
                    
                    
                      When I build apps, I've created objects
to help me manage things like users.
                      2:06
                    
                    
                      Some of the properties were username,
birthday, status and number of friends.
                      2:09
                    
                    
                      The methods were addFriend() and updateStatus().
                      2:14
                    
                    
                      I've also built simple games where I used
an object to store information about
                      2:17
                    
                    
                      the game state.
                      2:21
                    
                    
                      Like the score and whose turn it was and
other objects to represent the players.
                      2:22
                    
                    
                      I've also used objects when building
API wrappers to share on GitHub with
                      2:26
                    
                    
                      fellow programmers.
                      2:30
                    
                    
                      This is some pretty conceptual stuff and
right now it might not be super obvious
                      2:32
                    
                    
                      why objects are so useful or
how you'd use them in practice.
                      2:36
                    
                    
                      Don't worry.
                      2:40
                    
                    
                      As we move through this course, we'll
cover all the ways that objects can help
                      2:41
                    
                    
                      you reduce the amount of code you write.
                      2:44
                    
                    
                      Make your code easier to maintain and
modify and
                      2:46
                    
                    
                      help you create a code base
that's easy to understand.
                      2:49
                    
                    
                      A fun fact you may not know,
is that if you've been using JavaScript,
                      2:52
                    
                    
                      you've been using objects all along.
                      2:56
                    
                    
                      And you probably already have a pretty
good innate understanding of that.
                      2:58
                    
                    
                      In the next video,
we are going to explore that further, and
                      3:02
                    
                    
                      take a look at some objects you're already
really familiar with, like arrays.
                      3:05
                    
                    
                      This should help you get a clear
picture of how useful objects are and
                      3:09
                    
                    
                      why you might want to create your own.
                      3:13
                    
                    
                      Later on in the course,
                      3:15
                    
                    
                      we'll start digging into not only the
actual syntax of how we create objects.
                      3:16
                    
                    
                      But you'll also start training you
brain to think about object design.
                      3:20
                    
                    
                      And how and
when you should use them in your apps.
                      3:24
                    
                    
                      Come join me in the next video and
I'll see you soon.
                      3:26
                    
              
        You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up