What is javascript collision?

Any best practices around him?

+3
source share
5 answers

A JavaScript collision is when you have two global objects with the same name, and one another. For example, you can reference two libraries that use a function named $ in the root object (window) for the 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, like any other language:

var myApplication = {};

Then add any of the following functions / objects inside the namespace:

myApplication.init = function () {

}
+9
source
+3

, , , , javascript-based games.

javascript, , jquery , , - , - $.

0

Javascript , , , , , , .

<script>
  var foo = "test1";
  document.write(foo+"\n"); //test1+ a linebreak
  (function(){
    document.write(foo+"\n"); //test1+ a linebreak
    var foo  = "test2";
    document.write(foo+"\n"); //test2+ a linebreak
  })();
  document.write(foo+"\n"); //test1+ a linebreak
</script>
0

I thought this happened when Mummy Javascript and Daddy Javascript, who love each other, really want to appreciate children's Javascript.

My teacher was not very clear on this issue, however ...

0
source

Source: https://habr.com/ru/post/1746563/


All Articles