Skip to content

Instantly share code, notes, and snippets.

@dleitee
Created April 27, 2017 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleitee/b5f58a7d1347837055c69dcd5f9397b2 to your computer and use it in GitHub Desktop.
Save dleitee/b5f58a7d1347837055c69dcd5f9397b2 to your computer and use it in GitHub Desktop.
Creating immutable functions
// Example using Objects.assign
const changeName = (user, newName) => Object.assign({}, user, {
name: newName
})
// Example using destructuring assignment
const changeName = (user, newName) => ({
...user,
name: newName,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment