How to prevent XSS alter custom global javascript object & methods in WordPress

You’re not doing anything unusual or unsafe. You are just defining functions, which is a perfectly normal and reasonable thing to do with JavaScript. If there’s a malicious script running on your page then sure, it could redefine those methods, but it could also do other things that much worse.

This is why you need to make sure that malicious scripts can’t run on the page with basic practices like sanitisation and escaping. There’s no best practice about not defining functions. JavaScript wouldn’t work at all if you weren’t supposed to do that.