如何继承 C++ JavaScript 中的类?

发布于 2024-09-10 02:19:04 字数 239 浏览 2 评论 0原文

我正在嵌入 SpiderMonkey 以使我的 C++ 库可编写脚本。为了使其可扩展,我需要能够定义一个继承库的一个 C++ 基类的新类 (JavaScript)。

有没有一个例子告诉我如何使用 SpiderMonkey 来做到这一点?

I am embedding SpiderMonkey to make my C++ library scriptable. To make it extendable, I need it possible to define a new class (JavaScript) inheriting one C++ base class of the library.

Is there an example showing me how to do that using SpiderMonkey?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦与时光遇 2024-09-17 02:19:04

我认为您不能在 SpiderMonkey/JavaScript 中子类化 C++ 类并在其余 C++ 代码中透明地使用它。但是,您可以用 C++ 创建一个包装类,将其工作委托给几个 JavaScript 类/函数。如果您的 C++ 类可配置得足够好,那么它应该适合您的情况。 JSAPI 用户指南中解释了从 C 调用 JavaScript 代码和从 JavaScript 调用 C 代码页(我想您已经阅读过该页)。

I'd think you cannot subclass a C++ class in SpiderMonkey/JavaScript and use it transparently in the rest of your C++ code. However, you could create a wrapping class in C++ that delegates its work to a couple of JavaScript classes/functions. If you make your C++ class configurable enough that should work for your situation. Both calling JavaScript code from C and C code from JavaScript is explaind in the JSAPI User Guide page (I think you've already read that one).

在巴黎塔顶看东京樱花 2024-09-17 02:19:04

我不知道这是否可能,但感觉最好编写一个 包装类< JavaScript 中的 /a> 表示 C++ 库中的类。

I don't know it's possible, but a feeling says you're better off writing a wrapper class in JavaScript for the class in the C++ library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文