Javascript Namespacing. Does JS / Browser increase performance?

I fully understand why we should use the namespace in javascript, but mainly for organizational purposes and so that the global namespace is uncluttered ?. Does naming support affect browser / JS engine performance? Just wondering what your thoughts were. Thanks

+3
source share
2 answers

This technically hinders performance, but not really, depending on how deep you start. Silobox ( http://www.silobox.com/ ) is a JavaScript performance comparison tool, and we wrote a test that tests this. We found that the deeper the object was embedded, the longer the access to these properties.

So, for optimal speed, I recommend adding global quick access functions to your code.

Suppose you have:

var mycompany.myproj.Something = function(){ ... };

Good practice to include

var MCSomething = mycompany.myproj.Something;

Thus, when the JS engine is looking up MCSomething, it does not need to go down the trees. Google Maps takes this approach.

+4
source

. - , : ( ) .

+3

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


All Articles