Expose classless methods to javascript global scope?

I’m experimenting with Google AppScript using Haxe (made possible by Tong’s great externs: google-apps-script (0.2.0)).

There are some AppScript specific callbacks expected to live in the global scope, for example onEdit(event) wich is called whenever a spreadsheet cell is changed.

As far as I understand, the @:expose metadata makes a method reachable from the global scope, but only as a method of the Haxe-named class in wich it originated. Using Haxe classes in JavaScript - JavaScript - Haxe programming language cookbook

Is there a way of exposing a method directly as a property to the global scope without that class wrapper?

(Right now, i get around by post processing the generated .js file, but I would prefer doing it in native Haxe at one run, of course…)

// Jonas

This should work :slight_smile:

class MyClass {
 @:expose("onEdit") static function onEdit(event) {}


However, it doesn’t seem to work in AppScript - the application seems to bootstrap differently than mainstream javascript.

You could add a trigger function that’s called something else (not necessarily onEdit).

Also I’ve used Compiler.includeFile to prepend vanilla GAS-code in which I call into the Haxe-generated js.

P. S. On a side note, are you making use of clasp? (Command Line Interface using clasp  |  Apps Script  |  Google Developers). I use it as a post-build command to auto-upload to Google Apps. Speeds up development tremendously.


Yes, I found clasp the other day, and that got me into trying Haxe for app scripts as well as for anything else…! :slight_smile:

Using includeFile works fine. Anothe way is to just use a separate .gs file for the triggers, and forward the events to the haxe generated code from there.