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: Julian Turner <julian@baconbutty.com>
Date: Tue Jan 31 2006 - 18:15:54 CET

Julian Turner wrote:

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

Here is a quick example:-

var myObject=(function(){

    var myPrivateVar=1;
    var myPrivateFunction=function(){
        alert("Hello from Private "+myPrivateVar);
    }

    function Constructor(){}

    Constructor.prototype.alert=function()
    {
        myPrivateFunction();
        myPrivateVar++;
    }

    return Constructor;
})();

var o1=new myObject();
var o2=new myObject();
o1.alert();
o2.alert();

Regards

Julian
Received on Tue Feb 7 21:28:59 2006