Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericelliott/7017f78a42311ea485fa to your computer and use it in GitHub Desktop.
Save ericelliott/7017f78a42311ea485fa to your computer and use it in GitHub Desktop.

In JS FP do u ever extend objs with other objs? tweet

Yes, frequently to copy data from one collection to another during object creation, but once created and returned, objs are treated as immutable collections. Contrast against shared state with methods that mutate properties as in OOP. As a consequence of the immutable nature of collections in FP, pure functions boast stronger encapsulation features than private methods in OOP, because they guarantee against side-effects.

Unlike in OOP, most functions in FP are generic and independent of object properties and collection element contents, so there is typically no need to copy methods from object to object.

One major exception is that collections (or observable streams in FRP) may be enhanced with a number of functional utility methods which all return new values rather than mutating the properties of the parent object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment