Initially the history only contains one entry without any undo/redo function. But after the first change there should always be a function, so if the current function is undefined, I don't really think it makes sense to amend.
Technically, amend should only be called right after add is called (so the historyIndex would be in the last position). If amend is used otherwise and this didn't just return, I think it could break. Maybe if the function is undefined, I should log a console error saying that the use of amend may be invalid?