-
Notifications
You must be signed in to change notification settings - Fork 245
Closed
Description
Hi. At the end of the 2nd chapter you provide the following piece of code saying:
When the items variable is changed to reference another list of items, we’re in for a world of hurt—the todo API still works with the value items used to have, but items is referencing something else now.
var items = ['a', 'b', 'c']
var todo = checklist(items)
todo.check()
console.log(items)
// <- ['b', 'c']
items = ['d', 'e']
todo.check()
console.log(items)
// <- ['d', 'e'], would be ['c'] if items had been constant
function checklist(items) {
return {
check: () => items.shift()
}
}IMHO items and the checklist function are just forming a closure. So once that todo var is created and items is referenced to another thing, it doesn't matter what is done to items, it's irrelevant to the code.
I'm just a hobbyist so I thought someone should take a look at it.
Metadata
Metadata
Assignees
Labels
No labels