Pas2JS pascal source code
type
tt = class
private
function a: String;
begin
Result := 'a';
end;
public
procedure Test1;
begin
function SubTest1: String;
begin
var t := Self;
Result := t.a;
end;
var s := SubTest1;
WriteLn(s);
end;
procedure Test2;
begin
function SubTest2: String;
begin
Result := a;
end;
WriteLn(SubTest2);
end;
procedure Test3;
begin
function SubTest3: String;
begin
Result := Self.a;
end;
WriteLn(SubTest3);
end;
end;
var
tst := tt.Create;
tst.Test1;
tst.Test2;
tst.Test3;
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
a
a
a
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
var TObject={
$ClassName: "TObject",
$Parent: null,
ClassName: function (s) { return s.$ClassName },
ClassType: function (s) { return s },
ClassParent: function (s) { return s.$Parent },
$Init: function () {},
Create: function (s) { return s },
Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },
Destroy$: function(s) { return s.ClassType.Destroy(s) },
Free: function (s) { if (s!==null) s.ClassType.Destroy(s) }
}
function $New(c) { var i={ClassType:c}; c.$Init(i); return i }
function WriteLn(value) {
if (window.console) { window.console.log(value); } };
var tt = {
$ClassName:"tt",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,a:function(Self) {
return "a";
}
,Test1:function(Self) {
var s = "";
function SubTest1() {
var Result = "";
var t = null;
t = Self;
Result = tt.a(t);
return Result
};
s = SubTest1();
WriteLn(s);
}
,Test2:function(Self) {
function SubTest2() {
return tt.a(Self);
};
WriteLn(SubTest2());
}
,Test3:function(Self) {
function SubTest3() {
return tt.a(Self);
};
WriteLn(SubTest3());
}
,Destroy:TObject.Destroy
};
var tst = null;
/* <<< main JS >>> */
tst = TObject.Create($New(tt));
tt.Test1(tst);
tt.Test2(tst);
tt.Test3(tst);