Maybe you should check `typeof handler === 'function'` here, too?