3

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.

jowey
  • 7,581
  • 6
  • 27
  • 46
Shubham Takode
  • 525
  • 8
  • 24

1 Answers1

1

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375