0
It is known that closure is used to make variables within a function private and persistent.
We assume I use closure to modulate smaller functions, would be considered good practice? If not, what would be the best way to create a module preserving the privacy of some functions?
Follow firsthand code written by me:
Remark: I’m not sure if closure is the correct name for function below.
function ModuleCharacterCounter() {
function characteCounter(nome) {
console.log(`O nome ${nome} possui ${count(nome)} letras`)
}
function count(nome) {
return nome.length
}
return {
start(nome) {
return characteCounter(nome)
}
}
}
var counter = ModuleCharacterCounter()
counter.start('José')