initFormat 没有在我的代码中正确加入字符串

initFormat doesn't join the string correctly on my code

我正在研究 GCampax Gtk+Gjs 示例[1],想知道如何使用 initFormat。

据我所知,这是一个 JS 功能,可以将字符串和变量放在一起,例如

print("Hello, {0}".format("World"));  //--> Hello, World

但在 GJS 中似乎不能这样工作:

const pkg = imports.package
pkg.initFormat()
print("Hello,{0}".format("World"))  //--> Hello,{0}

我希望打印 Hello, World 但我得到的是 Hello,{0}。

帮助

[1] https://github.com/gcampax/gtk-js-app

initFormat() 向字符串添加 format() 方法。这些格式的工作方式与 C 和其他源自 C 的 printf 格式语言的语言类似,因此您需要编写 "Hello, %s".format("World").

但是,由于 JS 具有内插字符串,此功能已过时。只写这样的东西:

const target = "World";
print(`Hello, ${target}`);