Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between these 2 javascript functions? [duplicate]

Tags:

javascript

I want to know what is the difference between insideFn and outsideFn in the follwoing case :

 function Construct()
 {       
   this.insideFn = function(obj){
   ....
   }
 }

 Construct.prototype.outsideFn = function(obj){
      ...
 }

and which one is efficient to use ?

like image 737
Tom Rider Avatar asked Sep 18 '26 05:09

Tom Rider


1 Answers

In the first case every instance created with Construct will have its own insideFn, which will waste memory in case you will use more than one instance. In the second case each instance of Construct will have just a reference to outsideFn. So the latter is better.

like image 191
bjornd Avatar answered Sep 20 '26 19:09

bjornd



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!