Re: Variables and Object creation using prototypes
- From: nrlz@xxxxxxxxxxx
- Date: 30 Apr 2006 10:12:48 -0700
You answered (4) and you are correct! Well done!
Incidentally, this script does require a browser, because it uses the
"alert" function.
Cheer!
Nathar
Michael Winter wrote:
On 30/04/2006 12:33, nrlz@xxxxxxxxxxx wrote:
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: [],
addMember: function(m) {
this.members.push(m);
},
listMembers: function() {
return this.members.join(",");
}
};
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
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
.
- References:
- Variables and Object creation using prototypes
- From: nrlz
- Re: Variables and Object creation using prototypes
- From: Michael Winter
- Variables and Object creation using prototypes
- Prev by Date: Re: Variables and Object creation using prototypes
- Next by Date: Re: Cookie problem! Getting error when passing the expire date.
- Previous by thread: Re: Variables and Object creation using prototypes
- Next by thread: Re: Variables and Object creation using prototypes
- Index(es):
Relevant Pages
|