Learning Object Oriented Programming in JavaScript
This week is really our first week to dive into object oriented programming @ Austin Coding Academy. In my past the programming I have done was heavily in the functional area, so this is new ground for me. I see how important object oriented programming can be, since in real life your programming is often modeling an object (or thing) and this style of programming can help keep similar items together, and keep from having lots of redundancy in your code. So I am excited to learn a new style.
One of the most confusion for me so far in learning JavaScript is the many different syntax that can be used. One example is using the new arrow => function syntax over the older syntax of function nameFun(){}. Below is an example.
Note that with the arrow method the code can be completed with one line of code for smaller functions. The ability to be much less verbose than traditional functions is one of the key benefits.
We also are learning how to access information in an object. This can be done by using dot notation, or by destructuring the object. See examples below.
Another subject that is new to me is closure in JavaScript. Every function in JavaScript has a closure. And this is one of the coolest features of the JavaScript language. Because without closures, it would be hard to implement common structures like callbacks or event handlers. You create a closure whenever you define a function. Then when you execute functions, their closures enable them to access data in their scopes.