Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Javascript collision?

Tags:

javascript

Any best practices around it?

like image 343
Srikar Doddi Avatar asked Mar 05 '26 19:03

Srikar Doddi


1 Answers

JavaScript collision is when you have two global objects with the same name, and one overwrites another. For example, you might reference two libraries that both use a function named $ at the root object (window) for a query function. The idea is that you should use as few global objects as possible. The best way to do this is to create a namespace for any JS you write, just like any other language:

var myApplication = {};

And then add any subsequent functions / objects inside the namespace:

myApplication.init = function () {

}
like image 168
Shawn Avatar answered Mar 08 '26 08:03

Shawn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!