Object-orientated JavaScript

You’d be wise to invest some time learning the basics of object orientated programming (OOP). Here are some tips to get started and how to make use of it.

Object-oriented programming is intended to promote greater flexibility and maintainability in programming… By virtue of its strong emphasis on modularity, object oriented code is intended to be simpler to develop and easier to understand later on…

First I’d recommend you read Object-orientated JavaScript on the MDN.

Object-oriented programming may be seen as the design of software using a collection of cooperating objects, as opposed to a traditional view in which a program may be seen as a collection of functions…

The rough explanation

The most intuitive way of writing JavaScript (or any other thing) for me was to declare one function after the other, defining global variables as I needed them. This might actually work due to the forgiveness of the language but as things start getting advanced or when your need to implement a new feature, it’ll be complicated and things break.

You down with OPP (Yeah you know me) 3X
Who's down with OPP (Every last homie)
You down with OPP (Yeah you know me) 3X
Who's down with OPP (All the homies)

Source

Yea? If you recognize this pattern you should continue with the resources listed here. You identify your code, split it into several functions that call each other. You group common tasks into objects (classes) with methods (functions).

Example

Resources

Scope this in JavaScript