Re: Performance: inline- vs. prototype-defined methods ?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Performance: inline- vs. prototype-defined methods ?

From: Gerald S <e0125452@student.tuwien.ac.at>
Date: Tue Jan 31 2006 - 13:50:37 CET

Duncan Booth wrote:
> Yes it will make a difference since you will only be setting up the methods
> once instead of every time you create an object, also if you have a lot of
> objects you will be using less memory so there may be a gain there. Calls
> to the methods may be slightly slower but that is unlikely to be
> noticeable.

ok, thanks!!

but if i do it the .prototype-way, there is another problem. consider
the following situation:

   item = function () {
     var privateVar;

     function doInternalStuff();
   }

   item.prototype.myMethod1 = function() { .. }
   item.prototype.myMethod2 = function() { .. }
   item.prototype.myMethod3 = function() { .. }
    ...
   item.prototype.myMethod999 = function() { .. }

two issues:
     1) i can't access privateVar from my myMethodXXX methods (or can i?)
     2) i can't call doInternalStuff() from my myMethodXXX methods

i could expose both to the public, but is there a way to keep them
private AND use them. any patterns ?

thanks again ..

-
Gerald Stampfel
gstampfel@sedisys.com
Received on Tue Feb 7 21:28:39 2006