DEV Community

Discussion on: Encapsulation Explained using JavaScript

Collapse
 
ravavyr profile image
Ravavyr

I am not a fan of javascript terminology, however you wrote a nice explanation.

To me, encapsulation is just "when you use a function within a function or a class" the end.

Collapse
 
efpage profile image
Eckehard

Did you notice that there is a difference between classes and and objects? You can define a function within a class, but you cannot use it there. You will need to create an instance of the class (-> an object) to "use" a class method. But each object hast itΒ΄s individual, separated namespace and memory. THAT makes the difference.

Collapse
 
ravavyr profile image
Ravavyr

Frankly, it makes ZERO difference in about 99% of code any of us ever write. On rare ocassions you might create something where the memory usage actually affects performance, and then you generally just rewrite it or split it into more objects or functions and get it working better.

My comment was just about how javascript terminology sucks and really we don't need many of the terms with really complicated explanations when "a function within a function or class" suffices, that's all.