Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.karotte.org!news.bawue.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <1401647.V9SEqChMir@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 22 Jan 2012 14:14:36 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: Create array of a custom type Newsgroups: comp.lang.javascript References: <4bf1eb31-c97a-472c-a7ad-a9bffa4f0db4@g41g2000yqa.googlegroups.com> <4f1c0743$0$30171$a8266bb1@newsreader.readnews.com> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 31 NNTP-Posting-Date: 22 Jan 2012 14:14:36 CET NNTP-Posting-Host: a0754d41.newsspool3.arcor-online.net X-Trace: DXC=XNDaaUc=1F9n`gW2MTm]<3McF=Q^Z^V384Fo<]lROoR18kFDmU66W_Q;oDUG8: X-Complaints-To: usenet-abuse@arcor.de Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:10470 Denis McMahon wrote: > On Sun, 22 Jan 2012 03:55:03 -0800, Archos wrote: >> I've created a custom type named person: >> >> function person(name, age) {this.name=name; this.age=age;} >> >> Now, how to create an array (of 10 elements) of that new type? >> [10]person > > Not tested, but maybe you could start with something like: > > var i=10;var a=new array();while(i--)a[i]=new person("",0); > > and work out why it doesn't work (because it probably won't). Will you *please* stop wasting everybody's time by posting obviously erroneous solutions? Lack of code style aside, this works fine if you have that basic knowledge that it is `new Array' in ECMAScript implementations (case-sensitive). The easier, today irrelevantly less compatible expression is, of course, the empty Array initializer, `[]'. As `person' refers to a constructor, the identifier in the declaration and call should be `Person' by good convention, of course. PointedEars -- When all you know is jQuery, every problem looks $(olvable).