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

Performance: inline- vs. prototype-defined methods ?

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

hi,

got a performance problem; situation is as described below (see "Version
Inline"), i've got a javascript class item with many methods defined
inside and with every call to "new item()" the js interpreter has to
look through all the method definitions (did a profile using Venkman)
which takes too much time for me ..

would it make a difference if i define these methods outside the
constructor via .prototype (see "Version Prototype") ??

Version Inline:

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

Version Prototype:

   item = function () {

   }

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

many thanks in advance !!

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