> Try to guess what happens if I run the following code in any modern
> browser. [...]
A "modern browser" doesn't matter. Any correct ECMAScript implementation
will do.
> Will I get:
>
> 1) 1,2...a,b
> 2) a,b...a,b
> 3) null...null
> 4) 1,2,a,b...1,2,a,b
[snip]
> Group.prototype = {
> members: [],
[quoted text clipped - 7 lines]
> }
> };
The latter (4). The members array is a property of the prototype object,
not objects created via the Group constructor function. As each
resulting object will /share/ the properties of the prototype, any
properties added to it will accumulate and be accessible to all instances.
[snip]
Mike

Signature
Michael Winter
Prefix subject with [News] before replying by e-mail.
nrlz@hotmail.com - 30 Apr 2006 18:06 GMT
You answered (4) and you are correct! Well done!
Incidentally, this script does require a browser, because it uses the
"alert" function.
Cheer!
Nathar
> > Try to guess what happens if I run the following code in any modern
> > browser. [...]
>
> A "modern browser" doesn't matter. Any correct ECMAScript implementation
> will do.
[snip]
> The latter (4). The members array is a property of the prototype object,
> not objects created via the Group constructor function. As each
[quoted text clipped - 8 lines]
> Michael Winter
> Prefix subject with [News] before replying by e-mail.
nrlz@hotmail.com - 30 Apr 2006 18:12 GMT
You answered (4) and you are correct! Well done!
Incidentally, this script does require a browser, because it uses the
"alert" function.
Cheer!
Nathar
> > Try to guess what happens if I run the following code in any modern
> > browser. [...]
[quoted text clipped - 35 lines]
> Michael Winter
> Prefix subject with [News] before replying by e-mail.
> function Group() {
> }
function Group() {
this.members = [];
}
This might cause it to behave more like you'd expect. This way, the
'members' variable belongs to each instantiated Group object, rather than to
the shared prototype.

Signature
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
> Try to guess what happens if I run the following code in any modern
> browser. Don't cheat! Guess before you try it out.
Since when is this a quiz show? Get a life.
PointedEars

Signature
Multiple exclamation marks are a sure sign of a diseased mind.
-- Terry Pratchett
Randy Webb - 30 Apr 2006 22:08 GMT
Thomas 'PointedEars' Lahn said the following on 4/30/2006 5:04 PM:
>> Try to guess what happens if I run the following code in any modern
>> browser. Don't cheat! Guess before you try it out.
>
> Since when is this a quiz show?
Since when is it not? People ask questions, they may or may not get answers.
> Get a life.
You first.

Signature
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/