[Pas2js] Subclassing TJSArray

Mattias Gaertner nc-gaertnma at netcologne.de
Sat May 12 10:48:56 CEST 2018


On Sat, 12 May 2018 08:08:24 +0700
Ryan Joseph <ryan at thealchemistguild.com> wrote:

> > On May 11, 2018, at 11:18 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
> > 
> > A Pascal class cannot be created with the JS 'new' operator, as it
> > does not have a prototype. I added an error message.
> > 
> > I guess it is possible to descend from JS Array. A quick check revealed
> > that the length property is read only, while in a simple example it
> > works. I wonder what is the difference.  
> 
> But TVec2 is a TJSArray subclass so how do we construct it now? Those “new” constructors are all part of TJSArray but they’re sealed off now.

See rtl.js createClLassExt

It first creates an object for the type TVec2: Object.create(Array)
When you create an instance via a constructor it does:
Object.create(TVec2)

Alternatively you can provide an newinstance class function to
implement the latter part yourself.

Mattias



More information about the Pas2js mailing list