简体   繁体   中英

How to call Haxe compiled JS from outer JavaScript?

I have compiled my Haxe JS project, and it's working fine. What I have in Haxe is a Main class.

Now, I need to call a static function from a Haxe-compiled Main . I tried to call it like this:

Main.init();

But I get

Uncaught ReferenceError: Main is not defined

When I look in my compiled JavaScript script of Haxe I can see that Main is wrapped into something like that:

(function () { "use strict";

var Main = function() {

So, how to reach Main from external JavaScript code?

You can add @:expose metadata to make it accessible:

@:expose class Main

For more details, check out Exposing Haxe classes for JavaScript in the Haxe Manual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM