Forum > Free Pascal

Pas2JS missing language features ?

<< < (2/5) > >>

zburns:
Thaddy - do you have a demonstration - I'm also trying to figure out where/what I can use pas2js for and always looking for ideas.

Zack

dubst3pp4:
I'm also interested in the use-case of PAS2JS. Why use Pascal instead of JavaScript (with its ecosystem)?

In the wiki I've read that it has support to generate nodejs modules. But does it allow to interact with existing modules? (the Haxe language for example does this with 'externs' - you describe the API to an external JavaScript library / module, so the compiler does know about the external structure)

For me the biggest point would be the possibility to write the classes of my application logic only once: native Free Pascal classes which can be used for the server part of a web-application and to-JavaScript-compiled classes that I can use client-side in my own JavaScript code.

Sorry if my questions are too naive, but I had no time to seriously try PAS2JS ;-) ...btw, I would prefer a better name for the project! :-)

Thaddy:

--- Quote from: dubst3pp4 on January 17, 2018, 08:45:49 am ---I'm also interested in the use-case of PAS2JS. Why use Pascal instead of JavaScript (with its ecosystem)?

--- End quote ---
Mainly because Pascal is strongly typed as opposed to JavaScript: that means that the transpiler can generate more accurate code, less prone to errors, even if it outputs eventually JavaScript.
So you have the advantages of a strongly typed language while generating code for a weakly typed language. That includes e.g. debugging, type safety, etc. Pascal is often less verbose too.
Note that pas2js also supports inserting Javascript directly if you need it, through asm blocks, where the asm code is actual javascript.

Simply install the packages in Lazarus and you are good to go.

In reference to other questions: I will add some node.js examples to the wiki and a simple database application with client-side forms. Maybe Michael and Mattias can add even more: they are the experts.
I need to clean up the code so I can't do it today.

dubst3pp4:
Thanks Thaddy, more examples would be really great!

A little offtopic, but:
I was playing with Haxe lately - and although it also has strict type checks during compilation, the generated JavaScript code was not safe! I was a little bit disappointed by that fact, you could, for example, declare an object property as string, but the generated JS code did not declared that property with the help of Object.defineProperty and a related setter, which checks the type at runtime. Thus you can assign every type to that property of an instance of that type! So you can write type-safe-code, as long as you write the whole application in Haxe (because all the code gets compiled with type checking), but as soon as you write modules, which you want to use in other JavaScript code, the compiled code is even worse than hand-written code. Adding JavaScript type checking via setters for properties would be a real benefit of using PAS2JS!

PascalDragon:

--- Quote from: Thaddy on January 16, 2018, 06:44:31 pm ---What lacks are two features, one of which I deem important:that is anonymous methods.
But that would be for FPC itself to have first.

--- End quote ---

There isn't any reason why Pas2JS couldn't have anonymous functions before FPC.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version