Helper with Bind
by Antério Vieira
JavaScript
console.clear()
const action = normalize( (namespace, map) => {
return map.map( (target) => namespace + '-' + target + '-action' )
} )
const method = normalize( (namespace, map) => {
return map.map( (target) => namespace + '-' + target + '-method' )
})
function normalize (fn) {
return (namespace, map) => {
// change namespace
namespace += '-normalized'
return fn(namespace, map)
}
}
const namespaceHelper = (namespace) => ({
methodHelper: method.bind(null, namespace),
actionHelper: action.bind(null, namespace)
})
const {actionHelper, methodHelper} = namespaceHelper('h')
console.log(actionHelper([1,2,3]))
console.log(methodHelper([5,2,8]))