General practice guideline working with js libs vs regular Delphi objects

So, when working with WebCore libs created by the pas2js team, it looks like when we're dealing with any kind of object involving a TJSObject, we need to create new instances of them using the .new() operator, right? And as far as I can tell, we don't need to ever free or dispose of these, is that correct? If not, what do we call to free these things as needed?

(Sorry, I haven't worked with js in about 20 years. To me, it's pretty much like 'c' with a few odd quirks.)

But new instances of normal object pascal objects still get created via the .Create constructor calls?

If that's correct, would it make sense to encapsulate the JS objects inside of OP objects so everything follows the same .Create / .Free paradigm? (I expected the import libs created by the pas2js team to be like this this, but apparently they aren't.)

This is a think wrapper, to keep everything light & performant.
You basically use a JavaScript and its properties, methods with a Pascal syntax, nothing more.
You use .new() to create a JavaScript object instance. The browser normally does garbage collection but you can assign nil to objects to have the browser destroy it immediately.

1 Like