[Pas2js] call from external js files
Michael Van Canneyt
michael at freepascal.org
Tue Jun 18 08:00:27 CEST 2019
On Tue, 18 Jun 2019, pas2js at gauns.org wrote:
>
> hi guys,
>
> one last question concerning the external declarations
>
> i have this js file
> var logger = {
> name: "k1",
> getName: function() {
> return "k1 logger";
> },
> log: function(msg) {
> console.log(msg);
> }
> }
>
> and in my pascal file i use it this way
> type
> TExternal = class
> public
> name : String;
> function getName : String; external name 'getName';
> procedure log( aMessage : String ); external name 'log';
> end;
>
> var
> ext : TExternal; external name 'logger';
>
>
>
> the variable name i can use without the external declaration because in
> the js file its called also name,
> but with the function it doesn't work without the external declaration
> although the name of the function is the same
> Error: Forward procedure not resolved "log"
>
> would it be possible to write the class like this
> type
> TExternal = class
> public
> name : String;
> function getName : String;
> procedure log( aMessage : String );
> end;
>
> var
> logger : TExternal; external name 'logger';
>
> if the external name is the same?
>
> forget it if its to much work to change because its only esthetic
You can use (as I proposed originally) an external class definition:
(see the external name just after the class keyword)
TExternal = class external name 'anonymous'
public
name : String;
function getName : String;
procedure log( aMessage : String );
end;
var
logger : TExternal; external name 'logger';
Michael.
More information about the Pas2js
mailing list