This is yet another case of Confused by behaviour of nested functions , which is definitely an unfortunate gotcha of the language. As discussed in that thread, it’s usually better to conditionally return a different anonymous function rather than conditionally adding or redefining methods like that.
3 Likes