From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Object oriented to functional approach

Object oriented to functional approach - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Object oriented to functional approach

- [Instructor] 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 in 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…

Contents