我在使用jQuery-1.4.3 externs文件时特别看到了这一点.这个javadocs读取
/**
* @param {(string|number|function(number,number))=} arg1
* @return {(number|jQueryObject)}
* @nosideeffects
*/
jQueryObject.prototype.width = function(arg1) {};
Run Code Online (Sandbox Code Playgroud)
我有一个看起来像这样的电话:
var w = $(window).width();
$('#whatever').width(w)
Run Code Online (Sandbox Code Playgroud)
Closure抱怨:警告 - jQueryObject.prototype.height的实际参数1与找到的形式参数不匹配:( jQueryObject | null | number)required :( function(number,number):?| number | string | undefined)$('# .Xobni的')的高度($(窗口).height());
从玩游戏(删除可能的返回类型),我可以看到问题是第一次调用width可能返回一个jQueryObject,因为那不是一个有效的输入,Closure给了我一个错误.我尝试添加这个:
/**
* @type {number}
*/
var w = $(window).width();
$('#Xobni').width(w);
Run Code Online (Sandbox Code Playgroud)
但是然后Closure抱怨:警告 - 初始化变量found:(jQueryObject | null | number)required:number var w = $(window).width();
问题是当width接受一个参数时,它返回一个jQueryObject.当它不参数时,它返回一个数字.所以我知道我的电话没问题,但javadocs并没有完全反映出来,所以Closure警告我.有没有办法适当地修复javadoc或告诉Closure我知道这个结果将是一个数字.我知道我可以抑制错误,但我想知道如何更好地注释这些事情.
谢谢您的帮助!
我正在研究如何缩小javascript文件作为CI过程的一部分,以便我们可以在开发中使用未缩小的文件,并在部署到登台和实时服务器时自动压缩它们.
这是一个ASP.NET站点; 我们使用Hudson作为构建服务器.
我对Google Closure编译器很感兴趣,并且我遇到了这个.Net MSBuild Google Closure编译器任务,但它似乎并没有被广泛使用.是否有更好的选择与MSBuild一起使用,使用Closure或其他缩小工具?
msbuild continuous-integration minify google-closure google-closure-compiler
如何获取使用闭包模板创建的HTML?
<input name="fullName" class="large" type="text" data-validate="{required:true, minlength: 5, maxlength:100, messages:{required:'Please provide your Full Name.', maxlength:'This field can contain maximum 100 characters.'}}"/>
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
以下是我到目前为止所尝试的内容.
{namespace myApp.test}
/**
* Template for UI of Create User View
* @param userToEdit It is the object returned from GET on User Resource.
*/
{template .testUser autoescape="false"}
{{msg desc="<input id=\"fullName\" name=\"fullName\" class=\"large\" type=\"text\" value=\"{$userToEdit.FullName}\" data-validate=\"{required:true, minlength: 5, maxlength:100, messages:{required:\'Please provide your Full Name.\', maxlength:\'This field can contain maximum 100 characters.\'} }\" />"}}
{/template}
Run Code Online (Sandbox Code Playgroud)
返回Malformed attributes …
domA.style.display ="none"; domA.style.display ="block;
我在图书馆找不到这样的功能,但我猜他们必须在某个地方找到它.
如果您不关心缩小代码,有没有办法开始使用Google Closure库而无需设置subversion客户端并使用编译器?Google网站上的记事本示例程序是指
<script src="closure-library/base.js" > </script >
你能简单地在某处下载closure-library/base.js并开始玩UI示例吗?该封闭精简版快速入门版本不会出现包括goog.ui
我想在谷歌闭包(GC)环境中使用事件在我的对象之间进行通信.
假设我有两个类foobar.Boss和foobar.Employee.老板想知道员工什么时候煮咖啡,以及咖啡是否是咖啡因(他本周正在解雇咖啡因).
GC提供的类似乎提供了执行此操作的方法,goog.events.Event并且goog.events.EventTarget.
如果不知道更好,我认为它会像这样工作:
foobar.Employee.prototype.makeCoffee = function(isDecaf)
{
this.coffeeMaker.putCoffeeInMachine(isDecaf);
this.coffeeMaker.start();
var event = new goog.event.Event('COFFEE_ON', { isDecaf: isDecaf });
goog.events.dispatchEvent(event);
}
foobar.Boss.prototype.addEmployee = function(employee)
{
...
goog.events.listen(employee, 'COFFEE_ON', function(e)
{
if (e.target.isDecaf)
{
this.refillMug();
}
}, false, this);
...
}
Run Code Online (Sandbox Code Playgroud)
这是正确的模式吗?我对课程感到困惑goog.events.EventTarget- 目标调度事件如何?目标不是有事情发生的吗?
这个问题很有帮助,但更直接的答案将不胜感激.
当我尝试编译这个大豆模板时,Plovr引发了一个编译时异常.
// Copyright 2012 David Faux
/**
* @overview Lays out the home page.
*/
{namespace templates.home}
/*
* Lays out the home page.
*/
{template .main}
<h1>Hi! Welcome to my experimental page.</h1>
<img src="/images/logo.png" alt="" id="homeLogo" />
{/template}
Run Code Online (Sandbox Code Playgroud)
这是引发的错误.
org.plovr.CheckedSoySyntaxException:
template templates.home.main: Not all code is in Soy V2 syntax
(missing SoyDoc for template {template .main}).
Run Code Online (Sandbox Code Playgroud)
为什么我错过了这个模板的大豆文档?
我们正在尝试决定是否使用Dart构建Web应用程序.我们正在寻找一种在未来5年内保持高度相关性的技术.
现在EcmaScript 6规格即将出现(应该在2014年底之前),如果Dart真的能够长期存在,我们无法下定决心.
这是因为据我们所知,谷歌最初的Dash计划(现在的Dart)有一个缺失的部分.正如谷歌最初计划泄露的备忘录:
大型Google Apps的现有代码库如何?难道他们不得不重建一切来利用Dash吗?Dash Cross编译器应该能够采用类型化的Closure代码(有一些限制)并转换为Dash.尽管迁移过程不是完全自动的,但它应该更容易转移到Dash代码库.
因此,这就是这个问题的原因.到目前为止,谷歌有没有努力为Dart编译器或翻译器构建一个Closure(或GWT)?此外,您知道Google是否开始将其用于任何现有或新的制作网络应用程序?
换句话说,我们担心的是,Dart只会是一种语言,可以填补过渡期并推动Javascript更快地迭代,但只要主流浏览器支持ES6(和ES6 +),它就会被放弃.
我们不想对Dart的利弊开始任何争论,我们只需要一些可以帮助我们做出关键决定的事实信息.谢谢
如何使用Google Closure编译器删除未使用的代码?
我正在使用JQuery Slider控件但是我没有在JQuery中使用任何其他东西.所以我读到高级模式下的Google Closure编译器可以删除未使用的代码,但我不知道如何.
我有frontpage.html链接到我的网站上托管的html页面的外部JQuery,JQuery UI和JQuery Slider控件.
在我的frontpage.html上,我还在HTML中嵌入了JavaScript,启动了JQuery Slider控件.
我如何使用我使用在线Closure Compiler来评估我的frontpage.html,JQuery,JQuery UI和JQuery Slider来删除我不使用的所有未使用的JQuery代码?
javascript jquery jquery-ui google-closure google-closure-compiler