我正在试着将Annotorious (https://annotorious.github.io/#)更新到Closure / Javascript的最新版本。
当我使用“简单的”优化来编译它时,当调用goog.events.listen回调时,点语法函数似乎消失了。下面是一个例子:
下面是"main":
goog.provide('annotorious.Annotorious');
...
/**
* The main entrypoint to the application. The Annotorious class is instantiated exactly once,
* and added to the global window object as 'window.anno'. It exposes the external JavaScript API
* and internally manages the 'modules'. (Each module is responsible for one particular media
* type - image, OpenLayers, etc.)
* @constructor
*/
annotorious.Annotorious = function() {
/** @private **/
this._isInitialized = false;
/** @private **/
this._modules = [ new annotorious.mediatypes.image.ImageModule() ];
...在另一个文件中(它们都被编译在一起),我们有以下内容:
goog.provide('annotorious.Annotation');
goog.require('annotorious.shape');
/**
* A 'domain class' implementation of the external annotation interface.
* @param {string} src the source URL of the annotated object
* @param {string} text the annotation text
* @param {annotorious.shape.Shape} shape the annotated fragment shape
* @constructor
*/
annotorious.Annotation = function(src, text, shape) {
this.src = src;
this.text = text;
this.shapes = [ shape ];
this['context'] = document.URL; // Prevents dead code removal
}因此,我们启动代码,然后在编辑器中结束注释,监听“保存”按钮:
goog.provide('annotorious.Editor');
....
/**
* Annotation edit form.
* @param {Object} annotator reference to the annotator
* @constructor
*/
annotorious.Editor = function(annotator) {
this.element = goog.soy.renderAsElement(annotorious.templates.editform);
....
/** @private **/
//this._btnSave = goog.dom.query('.annotorious-editor-button-save', this.element)[0];
this._btnSave = this.element.querySelector('.annotorious-editor-button-save');
...
goog.events.listen(this._btnSave, goog.events.EventType.CLICK, function(event) {
event.preventDefault();
var annotation = self.getAnnotation();
annotator.addAnnotation(annotation);
annotator.stopSelection();
if (self._original_annotation)
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_UPDATED, annotation, annotator.getItem());
else
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_CREATED, annotation, annotator.getItem());
self.close();
});如果我把断点放在"goog.events.listen(this._btnSave...“)上,然后输入"annotorious.Annotation",我会得到我期望的结果:

实际上,它有各种各样的方法:

然后我释放代码,并中断侦听器(event.preventDefault();,等等,如上所示):
现在,所有的点语法方法都消失了。

当然,这会导致随后的崩溃。
所有这些文件都是一起编译的。
这发生在所有的回调中-- 'load‘事件,其他ux回调,等等。
这必须在以前版本的Closure / JS中起作用。
这可能是什么原因造成的?
谢谢!
发布于 2019-09-26 01:40:44
好的,我可以通过向闭包编译器命令行添加"--assume_function_wrapper“来解决这个问题。
以前,我是使用Plovr编译包的。然而,由于Plovr很长一段时间没有更新,我转而使用闭包编译器。
显然,要么是Plovr在内部提供了'--assume_function_wrapper‘,要么是Plovr使用的编译器版本没有破坏所描述的函数。
正如@john上面建议的那样,我敢打赌'--assume_function_wrapper‘可以通过重新声明名称空间来防止goog.provide“破坏”它们。
https://stackoverflow.com/questions/57740161
复制相似问题