Geequlim / ECMAScript

Javascript binding for godotengine
MIT License
959 stars 84 forks source link

Global pollution #187

Open Hadaward opened 7 months ago

Hadaward commented 7 months ago

I personally don't really like global pollution, you could take advantage of the javascript module system to export godot methods, utilities and classes without needing to register the godot namespace into the global. If you are wondering how this would work, it is quite simple, the first thing needed would be a d.ts documentation file for intellisense to work. And then we can consume the godot api using import syntax:

import { Node2D, print } from "godot";

export class Main extends Node2D {
  _ready() {
    print("Hi from Javascript Main class");
  }
}

This is literally the only thing I dislike about this api, the godot api is simply thrown into the global scope.

snatvb commented 3 months ago

I think this is limited engine - C++ <-> JS, you can bind data into JS from C++ only in global object. Actually another languages with runtime has similar behaviour

Hadaward commented 2 months ago

I think this is limited engine - C++ <-> JS, you can bind data into JS from C++ only in global object. Actually another languages with runtime has similar behaviour

Hmm, I don't know what to say about this because I've already found libraries in C#, for example, that allowed running javascript engines and exporting objects as modules to be imported. So i dunno if there's a lib like that in C++