- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 Google 闭包中注释 JSON 响应的接口(interface)?
我必须使用 JSONP 接口(interface),它实际上将一些 XML 转换为 JSON 并将其作为参数提供给我的回调。但不幸的是,原始 XML 包含一些属性,因此我得到一个带有 @attributes-fields 的 JSON 对象,例如
{
"output": {
"foo": "bar"
},
"@attributes": {
"baz": "attr"
}
}
我创建了一个 google-closure 接口(interface),这样编译器就不会意外缩小我的字段,并且我在 IDE 中获得了简洁的自动完成功能。
/**
* @interface
*/
var JsonResult = function() {};
/**
* @type {JsonResultOutput}
*/
JsonResult.prototype.output;
/**
* @type {JsonResultAttributes}
*/
JsonResult.prototype['@attributes'];
/**
* @interface
*/
var JsonResultOutput = function() {};
/**
* @type {string}
*/
JsonResultOutput.prototype.foo;
/**
* @interface
*/
var JsonResultAttributes = function() {};
/**
* @type {string}
*/
JsonResultAttributes.prototype.baz;
不幸的是,如果我尝试在括号和字符串中注释字段,编译器会发出警告。所以我现在的问题是:我应该如何注释它以删除警告?也许我可以在界面中删除这个字段,因为我也必须在代码中以相同的方式编写这个字段,所以编译器永远不会缩小这个字段。但我还想记录该对象的完整结构。
最佳答案
对我来说这看起来像是一个错误。请随时通过 https://github.com/google/closure-compiler 提出问题
要解决此问题,您必须使用对象文字键:
JsonResult.prototype = {
/**
* @type {JsonResultAttributes}
*/
'@attributes': {}
};
关于javascript - 如何在 google-closure 接口(interface)中注释 @attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35724828/
我刚刚开始使用 Google Closure 做一些工作,我想将选择字段的创建移动到它自己的模板中,并使用类似以下内容调用该模板: {call templates.utils.select} {p
我有一些代码,简化后看起来像: fn foo() -> Vec { unsafe { unsafe_iterator().map(|n| wrap_element(n)).co
我正在从脚本内部调用Closure Compiler(closurecompiler.jar)。该脚本还生成Closure Compiler需要编译的一些javascript。有没有办法将此JavaS
以下示例代码生成有关高级优化的编译器警告:“JSC_UNSAFE_NAMESPACE:为命名空间 NS 创建的别名不完整”。如果我删除@enum 注释,它不会发出警告。 var NS = {}; /*
看代码: let add_one = |&: x| { 1 + x }; 我知道x是闭包参数,但是闭包中的&:是什么意思? 最佳答案 这是 Rust 的一个文档不足的部分(并且过时,请参阅评论)。我知
PHP manual for anonymous functions (即闭包)指出: Anonymous functions are currently implemented using the
我从脚本内部调用 Closure Compiler (closurecompiler.jar)。该脚本还生成了一些 Closure Compiler 需要编译的 javascript。有没有办法将这个
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 7年前关闭。 Improve t
当鼠标在文档正文中移动时,我试图调用一个函数。但是,下面的事件处理程序不起作用。 goog.events.listen(document, 'onmousemove', function(e)
我试过了 java -jar compiler.jar --js jj.js --js_output_file jj.js 输出文件大小为 0。 如果我不想从 .min.js 重命名为 .js,我该怎
Google Closure UI库如何与Google DART一起使用? 最佳答案 Dart没有使用JavaScript库的功能。这是设计使然,因为Dart旨在同时针对Dart VM和转换为JS的D
是否可以使用 Google Closure 编译器在两个文件中定义一个类?例如,如果我自动生成一个类并希望为用户输入的代码保留另一个类: 在 MyClass.AutoGenerated.js 中 go
当我在 http://closure-compiler.appspot.com 处的闭包编译器中测试以下代码时: // ==ClosureCompiler== // @output_file_name
是否可以使用 Google Closure 编译器在两个文件中定义一个类?例如,如果我自动生成一个类并希望为用户输入的代码保留另一个类: 在 MyClass.AutoGenerated.js 中 go
当我运行闭包编译器时,会收到一堆这样的警告: [exec] jquery/3.2.1/dist/jquery.js:733: WARNING - Suspicious code. The resul
假设您正在一个具有多个外部库依赖项的 javascript 项目中工作,并且想要在 ADVANCED_OPTIMIZATIONS 模式下使用 Google Closure Compiler 编译您的源
我正在为 PIXI.js 库准备 externs。我收到以下警告: js/Test.js:188: WARNING - Property position never defined on PIXI.
我最近使用 Google 的 Closure 编译器创建了一个 JavaScript 库:https://github.com/bvaughn/task-runner 我打算让这个库供那些也需要完整闭
我正在尝试自学闭包模板。我做了一个简单的文件 simple.soy: {namespace examples.simple} /** * says hello to the world * @pa
我正在将一个项目从 jQuery 迁移到 Closure。我有一些我想编译的只迁移了一半的代码。未编译的源工作正常。我想知道使用 SIMPLE_OPTIMIZATIONS 编译它的编译命令。 原始基于
我是一名优秀的程序员,十分优秀!