goog.require关闭.编译错误

Closure goog.require. Compile error

本文关键字:错误 编译 关闭 require goog      更新时间:2023-09-26

我在我的项目中使用了Google闭包库和编译器。

下一个字符串出现奇怪的错误:

if (!properties.name) {
    throw {message: 'Widget name expected'};
}
properties.name = properties.name.toLowerCase();
goog.require('DOMless.' + properties.parent);
goog.require('DOMless.' + properties.parent);
// ERROR - Syntax error in JS String literal

怎么了?

goog.require是Closure编译器的一个特定指令,它将从脚本中删除。

由于它不被JavaScript引擎解释,我认为你根本不能使用字符串以外的东西作为参数