Puzzling question about JS prototypes

J

John G Harris

The perfect pattern to build an inheritance chain: d inherits from c
that inherits from b that inherits from a:

d= object(c= object(b= object(a= {})));

Try to write that in a single line using 'new'...

Now try to create another object of the same kind.

Which is easier :
d1= object(c1= object(b1= object(a1= {})));
or
new Thing();
and which causes less pollution of the global namespace?

You also missed out the
a.init(...); b.init(...); c.init(...); d.init(...);

John
 
J

Jorge

(...)
Which is easier :
  d1= object(c1= object(b1= object(a1= {})));
or
  new Thing();
and which causes less pollution of the global namespace?
(...)

You probably mean new ThingA() plus new ThingB() plus new ThingC()
plus new ThingD(). 4 different constructor functions. And still the
constructors' prototypes have to be setup *outside* of the constructor
functions. Now that's 'pollution'.
 
J

John G Harris

On Thu, 9 Apr 2009 at 08:46:01, in comp.lang.javascript, kangax wrote:

[[Construct]] also happens to invoke the function object in question
(see step 6) and it is this invocation that might not be desirable and
which was the main reason behind preferring "beget"/"clone"-like object
creation.

So why not use a different function object, such as the one hidden
inside beget.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top