Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #10470

Re: Create array of a custom type

Message-ID <1401647.V9SEqChMir@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-01-22 14:14 +0100
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

Followups directed to: comp.lang.javascript

Show all headers | 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


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