So welcome to Object Oriented Programming in JavaScript. If you've been taking all my classes at this point, you will have learned object oriented programming in Python. You will have learned object oriented programming in PHP. And now you're going to learn object oriented programming in JavaScript. And actually [LAUGH] you'll see that I just sort of borrow the same lecture slides for each of them and then change the code. And that's because the underlying notion of object orientation, sometimes we have a couple of different terminologies for it in different languages. But the notion that this is template, which we call a class, then within the class, we define code, which is method or messages and data which is attributes. And then we take this template, the cookie cutter and then make a cookie, and these cookies the real things, not the shape of the thing but the real things are called objects or instances. So that is true across all object oriented patterns. You might as well get that. And that's why I particularly love teaching object orientation in multiple languages. Because if you really learn it, you're like, yeah, okay. This is just a little different syntax. Now what we're going to find is that JavaScript has its own unique, and I think very cool spin on object orientation, but the basics are still the same. So just like in all object oriented concepts, the class is this template. It's the characteristics, it's a blueprint. Dog is this generic thing trait shared by all dogs, breed, fur color, etcetera. And instances when we stamp something out and so in our little cookie model, the cookies are all the instances. And you'll notice that some cookies are decorated one way, and some cookies are decorated another way. But you can see they all eventually came from that template. The other word we use for instance is object. So class and object, or class and instance. Probably instance, I think, captures the idea better, because it's like you can have more than one instance. You have one class and then you can make more than one instance of that class. You can have one class or you can make more than one object from that class. It's very equivalent, but I think instance captures the idea a little bit better. Method, again an object is a program inside of a program, we have some data structures inside the program. And we have code. And the code sort of manipulates the data structures and solving your problem is a combination of building clever data structures, and then clever code that makes use of those data structures to solve the problem. And sometimes you put more of the cleverness in the data structures, and sometimes you put all the cleverness in the code. So there's a balance between in how you use data structures, and how you use code to achieve things, and the same is true in an object. So program is big and an object is kind of like it's own little siloed wall of stuff with code inside of it and data inside of it. And ways that we talk to it and get stuff out of it etcetera. The term of method is a function that lives inside of a class, i.e., also lives inside objects when we create them. So, the object oriented pattern in JavaScript is a little different. It is like a store and reuse pattern, and the function in core JavaScript is the same, but it's different. The function keyword itself is executable, and it has a return value. So what you're think of normally is when you say, function, blah, you make this piece of new thing with a name blah, and that's it. But in JavaScript, that actual function, statement is an executable statement, and so you can say, X = function () blah. The point is, is this is defining a function, if we name this y, it defines the function but it also returns the code of the function so you can put that in a variable. And that's really cool, that is a very different way of thinking of simply a function. I first programmed in Fortran and we called them subroutines and we called them functions as well. And you say, subroutine and then it's naming a thing and storing and retrieve a pure store and reuse. In JavaScript it's store and reuse, but you also get a return value from it. And so that's what we use to do object oriented programming. So this is called in computer science first-class functions, which means that functions are just more data. So code and data are more equivalent. And first-class function is like, well you can take the code of something and you can sign that code into a variable and you can carry that code around. And so this is an essential founding architectural concept in JavaScript. And so it actually profoundly changes how you code in JavaScript. And, like I said before, JavaScript is the wrong language to learn as your first language. But it's a great language to learn as your fourth language because it's like, wow, you can understand this kind of stuff, because if I just started taking functions and assigning them to variables, you'd be like no, I don't understand so I love Python as first programing. So up next we're going to like take all these ideas and write some sample codes and take a look at how objects work in JavaScript.