0

I'm looking for general guidance (eg. bullet points on what to consider) on how to ensure a JavaScript heavy app doesn't run into any conflicts with extensions.

For example, I found that I had a global function called log, which a specific extension somehow overwrote. Since extensions can load code at various times, I'm curious what general ideas (or links/articles) people have to ensure no conflicts.

One I've discovered recently is also assume that all 3rd party scripts (from a domain other than yours) may get blocked by some over-zealous Ad Blocker, and act accordingly (eg. always check to ensure any objects or methods you're expecting to be available from those 3rd-party scripts, are in fact available, before calling them).

Appreciate any guidance or ideas here.

As for a specific question:
Is it at all problematic to extend native objects (eg. via String.prototype.trim = function() { ... };?

onassar
  • 3,313
  • 7
  • 36
  • 58
  • Try to minimize the use of global variables. You should use modules or self invoking functions wherever possible. You could also keep all your globals under a specific object and operate with that. You don't need to to rewrite native objects or prototypes. It's generally a bad practice. You can create your own objects and use those. – caisah Nov 17 '17 at 18:22
  • Can you point me to any articles or guides that talk about prototyping native objects not being a good idea? I'd like to learn the reasons for that. I agree that it could cause issues (again, with extensions), but it's also so clean (when the object is native). – onassar Nov 17 '17 at 22:29
  • An extension can overwrite or even undo your globals and native object modifications. – wOxxOm Nov 18 '17 at 05:59
  • https://stackoverflow.com/questions/14034180/why-is-extending-native-objects-a-bad-practice – caisah Nov 18 '17 at 06:50
  • Thanks for the link @caisah I'll give this all a read – onassar Nov 18 '17 at 09:22

0 Answers0