Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does using const variable in angularjs factory makes positive impact on performance?

In javascript we can change properties of constant object. So if I have some factory in AngularJs defined as below

      myApp.factory('sampleFactor', function() {
        var sampleFactoryVar =  {
         setFoobar: function(foo){
             //perform some operations
             return foo;
         },
         getFoobar:function(){
             //perform some operations
         }
       };
       return sampleFactoryVar;
     });

In this factory if I will be declaring sampleFactoryVar as const will it make any significant impact on performance ? Please consider sampleFactoryVar is holding lots of properties.

like image 358
Shubham Takode Avatar asked Aug 10 '26 06:08

Shubham Takode


1 Answers

No, it won't have any effect at all. You could in fact just omit the variable declaration and just return the object literal directly. However the factory is only called once, so performance hardly matters here anyway.

like image 91
Bergi Avatar answered Aug 12 '26 21:08

Bergi