Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10470
| 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> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| 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<]lROoR18kF<OcfhCO;?F<P;FJ26_2DZm8W4\YJN<;?f@h5gMfb<MFMO?;>DmU66W_Q;oDUG8: |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.javascript:10470 |
Followups directed to: comp.lang.javascript
Show key headers only | View raw
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).
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Create array of a custom type Archos <raul.san@sent.com> - 2012-01-22 03:55 -0800
Re: Create array of a custom type Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-22 12:55 +0000
Re: Create array of a custom type Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-22 14:14 +0100
Re: Create array of a custom type Martin Honnen <mahotrash@yahoo.de> - 2012-01-22 13:57 +0100
csiph-web