Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The problem here is that this conversation is made complicated by the fact that plain objects in JavaScript are not what is really being talked about when people say the term OOP. So to clarify, stateful classes would be what I am talking about when I use that term. The foundation of OOP is based on tying state with functions in what are deemed "Objects". This implicitly makes all methods in an Object that depend on or modify an Object's internal state impure functions. And the purpose of most Objects methods are for the purposes of doing those things. Basically if you use stateful classes that encapsulate state and modify their own internal state with functions you are not doing functional programming. These two paradigms are in fact at odds and not compatible.


> This implicitly makes all methods in an Object that depend on or modify an Object's internal state impure functions

Note that you can have methods which do not depend on mutable state. In ES6 you can FREEZE objects, which you could do in the constructor. Freeze the object after having set its "instance variables". Now all methods of that object are "pure functions". So you can choose. Choose to create pure functions or impure.

Creating a new immutable instance really is equivalent to creating a set of immutable ('pure' if you like) functions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: