Gerald S wrote:
> 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 ?
There are.
Search this group for posts from Richard Cornford: there have been
plenty of discussions on this subject.
Take a look at:-
<URL:http://www.litotes.demon.co.uk/js_info/private_static.html>
<URL:http://jibbering.com/faq/faq_notes/closures.html>
<URL:http://www.crockford.com/>
Regards
Julian
Received on Tue Feb 7 21:28:54 2006