4 ms·
Review: Consider replacing: return function(method) { switch (method) { case 'getFullName': return getFullName; case 'setFirstNam
by erikerikson 6y ago
Review:
Consider replacing:
return function(method) {
switch (method) {
case 'getFullName':
return getFullName;
case 'setFirstName':
return setFirstName;
}
}
With:
return {
getFullName,
setFirstName,
}
And leaving client code unchanged.
This leaves callers with a struct but is cleaner and more direct. So far as I can tell, modules and closure usage are objects in JavaScript.
I'm curious if you might have insight into what this approach might block other than exclusively using functions?
- stopachka 6y agoHey erikerikson -- I think your solution is indeed equivalent, and I would say even more idiomatic js. The reason I chose the first option, was to really bring home the point that all of this could be expressed with closures.