使用Haxe访问外部JavaScript库 [英] Access external JavaScript libraries using Haxe

查看:74
本文介绍了使用Haxe访问外部JavaScript库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何从Haxe访问外部JavaScript库. extern类的源文件应该与相应的本机JavaScript文件以及"main" Haxe源文件位于同一文件夹中,还是可以在单独的源文件夹中进行定义?

I'm trying to figure out how to access external JavaScript libraries from Haxe. Should the source file for the extern class be in the same folder as the corresponding native JavaScript file, as well as the "main" Haxe source file, or can they be defined in separate source folders?

这是我要参考的文档:

https://haxe.org/manual/target-javascript-external -libraries.html

此外,Haxe是否有任何文档说明如何访问所有目标(而不是仅一个目标)中的外部库?

Also, is there any documentation for Haxe that explains how to access external libraries in all targets (as opposed to just one target)?

推荐答案

Extern机制假定已定义的类型在运行时存在(可以调用/使用它们),但不假定如何定义这些类型以及在何处定义这些类型.所有平台都是如此.

The Extern mechanism assumes that the defined types exist at runtime (they are available to be invoked/used) but assumes nothing about how and where those types are defined. This is true for all the platforms.

项目中如何包含extern库主要取决于目标,并且变化很大.

How the extern libraries are included in your project mostly depends on the target and can vary greatly.

对于JS,外部定义(.hx文件)与包含这些类型的JS(js库)之间没有直接关联. haxe文件应可由haxe访问(使用-cp-lib或将其放在源目录中),而js文件应可由运行时访问(在haxe生成的代码之前在HTML中包含lib JS) .

In the case of JS, there is not a direct association between the extern definitions (.hx files) and the JS that includes those types (js library). The haxe files should be accessible by haxe (using -cp, -lib, or putting them in your source directory) while the js files should be accessible by the runtime (include the lib JS in your HTML before the haxe generated code).

可能引起混淆的是Haxe支持一项功能,该功能允许您将外部js文件嵌入生成的代码中.这样,您只能分发一个文件,而不是一个主文件和一个或多个lib文件.您可以看一下Haxe如何自动包含JQuery __init__() .

What might create some confusion is that Haxe supports a feature that allows you to embed an external js file inside the generated code. This way you can distribute only one file instead of a main file + one or more lib files. You can have a look at how Haxe automatically includes JQuery in __init__().

这篇关于使用Haxe访问外部JavaScript库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆