Oops - had an extra bare function() declaration that I'd meant to remove (was needed until I put the method generation in a separate function).