Skip to content

Instantly share code, notes, and snippets.

@Kikobeats

Kikobeats/index.js

Last active Sep 6, 2017
Embed
What would you like to do?
ES6 Pure & self documented Functions.
/**
* ES6 Pure & self documented Functions.
*
* Why Pure?
*
* A pure function is a function where the return value is only determined
* by its input values, without observable side effects.
*
* Why Self-documented?
*
* Extract all the object path in the first line with the destructuring, so
* you know all the input that the function receive.
*
* If you have less than 4 variables, you can declare it like:
* function readFile (filepath, filename, permissions) {}
*
* Otwerwhise use object approach.
*
* for Async functions, pass callback after opts
* function readFile (opts, cb) {}
*
*/
function readFile (opts) {
const { filepath, filename, permissions } = opts
console.log(`reading file '${filename}' at ${filepath} with ${permissions} mode`)
}
readFile({filepath: '~/HOME', filename: 'test.txt', permissions: '644'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment