[Pas2js] Subclassing TJSArray

Mattias Gaertner nc-gaertnma at netcologne.de
Fri May 11 16:23:57 CEST 2018


On Fri, 11 May 2018 16:47:49 +0700
Ryan Joseph <ryan at thealchemistguild.com> wrote:

> I was curious if I could subclass an array without it being external but I got a compile error as seen below. If I move Get/SetElements to public then it compiles but the JavaScript seems wrong. Bugs or not implemented yet? 

Get/SetElements are not real functions. They are translated to the JS
bracket accessors and can be used by array properties. Since there is
no need to call these pascal methods directly I have not implemented it.
I have now implemented a few cases and added errors for other uses.

 
> ========
> 
> type
> 	TVec2 = class (TJSArray)
> 		private
> 			procedure SetX (newValue: GLfloat);
> 			procedure SetY (newValue: GLfloat);
> 
> 			function GetX: GLfloat;
> 			function GetY: GLfloat;
> 		public
> 			property x: GLfloat read GetX write SetX;
> 			property y: GLfloat read GetY write SetY;
> 	end;
> 
> procedure TVec2.SetX (newValue: GLfloat);
> begin
> 	SetElements(0, newValue);

This simple case now works in trunk.
But the recommended way is to do

Elements[0]:=newvalue;

> end;
>[...]

Mattias


More information about the Pas2js mailing list