gnome - 在 GJS 中包含二级来源
问题描述
我正在开发一个 Gnome 扩展。因此,我有一个extension.js
我所有代码所在的位置。现在我有一些我想使用的其他代码,它存在于一个文件中foo.js
,遗憾的是还没有使用严格模式。我怎样才能加载这个foo.js
?
解决方案
这在现有教程中有所介绍:
// GJS's Built-in Modules are in the top-level
// See: https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Modules.md
const Gettext = imports.gettext;
const Cairo = imports.cairo;
// GNOME APIs are under the `gi` namespace (except Cairo)
// See: https://gjs-docs.gnome.org/
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
// GNOME Shell imports
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
// You can import your modules using the extension object.
// For example, if you had a file named `exampleLib.js` in your extension directory
const Me = ExtensionUtils.getCurrentExtension();
const ExampleLib = Me.imports.exampleLib;
let myObject = new ExampleLib.ExportedClass();
ExampleLib.exportedFunction(0, ExampleLib.EXPORTED_VARIABLE);
推荐阅读
- r - 在 data.table 中按组计数快速前 N
- java - 无法跳过通过的测试用例并仅在 testNG 中测试失败的测试用例
- c# - 为什么自定义 SharePoint 计时器作业只能处理列表中的一半项目?
- python - 适用于 Windows .NET 或 python 的视频编辑器桌面应用程序
- java - sonar-scanner-maven 在分支构建上失败
- netlogo - 通过 patch-ahead NetLogo 获取多个补丁
- c - Event.h 库在 C 中使用 event_new() 函数
- javascript - 使用 HOC 可拖动元素反应 DnD 引发无法设置未定义错误的属性“道具”
- java - 将 PowerMockito 与静态方法一起使用时出现异常
- javascript - 选择使用 Angular 2 显示选定值的对象