Secret Life of objects
On their simplest, objects are just a paradigm one uses to organize his programs.
- It uses objects as the main mean of program organization
Encapsulation
The idea of bundling your piece of codes into manageable capsules is a technique used in object oriented programming, this promotes a high level of abstraction, thus less coupling with the way codes interact with each other.
Encapsulation allow us to hide the implementation details of how things are implemented for each object and only expose a low footprint methods to interact with the outside world.
The pieces of code that are exposed have the public access modifier, meaning, codes outside the scop of that object exposing these methods can be accessed for other things that do not need to be exposed but still are necessary for the operation of the object, are kept private.
Limitation of JavaScript
JS is not build with the whole idea of access modifiers in mind. to communicate that something is private for example, developer uses and underscore(_
) in front of the property to better communicate their intent
Methods
Methods are nothing more than functions inside of objects. surely, they would have sticked to functions, but then methods are even better because they are mean to better communicate what your code is.
this binding
this
simply refer to the object that is being used when calling a property or rather a method. A method usually needs to perform something onto the object that it was called upon. now how do you refer to that object inside of your method ? this is when the this keyword comes in handy.
- You can change the context of this, when calling your function or method, using bind, call or apply