[Pas2js] anonymous classes implementation
warleyalex
warleyalex at yahoo.com.br
Thu Dec 20 18:10:35 CET 2018
Is there a way to replicate this literal JS structure using anonymous
classes?
list: [
{fieldA: 'fieldA1', fieldB: 'fieldB1'},
{fieldA: 'fieldA2', fieldB: 'fieldB2'},
{fieldA: 'fieldA3', fieldB: 'fieldB3'}
]
Of course, you can use new([]), but I think we can use the anonymous
functions and the transpiler replicate literal objects.
//-----pas2js using anonymous classes------------------
type
THandleArray = array of JSValue;
function list: THandleArray;
begin
result := [
CLASS
l := 'fieldA1'; external name 'length';
w := 'fieldB1'; external name 'width';
END,
CLASS
l := 'fieldA2'; external name 'length';
w := 'fieldB2'; external name 'width';
END,
CLASS
l := 'fieldA3'; external name 'length';
w := 'fieldB3'; external name 'width';
END];
end;
//-----------------------
//--the compiler pas2js should emit this pure literal //---------------
function list() {
var Result = [];
Result = [{
"width" : "fieldB1"
,"length" : "fieldA1"
}, {
"width" : "fieldB2"
,"length" : "fieldA2"
}, {
"width" : "fieldB3"
,"length" : "fieldA3"
}].slice();
return Result
};
------------------
OUTPUT:
[{"width":"fieldB1","length":"fieldA1"},
{"width":"fieldB2","length":"fieldA2"},
{"width":"fieldB3","length":"fieldA3"}]
--
Sent from: http://pas2js.38893.n8.nabble.com/
More information about the Pas2js
mailing list