From the course: Learning Functional Programming with JavaScript ES6+

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Converting object-oriented to functional code

Converting object-oriented to functional code - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Converting object-oriented to functional code

- If you're coming from an object-oriented background, it may seem strange to you that functional programming places an emphasis on keeping data and functions separate. Since one of the central concepts of object-oriented programming is that we put data and the functions related to that data together in objects. To understand why it makes sense to keep data and functions separate and functional programming, it might be helpful to think about why we keep them together in object-oriented programming in the first place. The main reason that it's useful to keep data and functions together in the same object is that this allows us to interact with the member variables of an object without touching them directly. What's wrong with touching variables directly? Well, if we give programmers direct access to variables, they can, and in my experience, will change them in ways that they're not supposed to. Consider the simple case of a person object with publicly accessible properties, first…

Contents