English 中文(简体)
在使用图书馆时如何利用关闭汇编员?
原标题:How to take advantage of closure compiler when using a library?

最近,我利用了从古角度讲一些促进守则和部分执行的巨大工具,例如,它会采取下列行动:

//Just an alias for an elementByID selector
function $(bar){
    return document.getElementById(bar);
}

//Call the selector
alert($("foo").value);

并且将其缩短为<代码>alert(文件getElementById(“foo”));,从优化的角度来说,这相当令人不安。

我只想解释这一点,因为我想这一概念对大图书馆如“ j”有好处,而“Qu”这样的大型图书馆基本上试图抹去 Java文中的一nch,就像通过国际发展学会选择的那样。

在快速测试中,我把整份金字生产文件装上汇编器,并附上了在末的单一文本:alert($($)“#foo”);

很可悲的是,汇编者无法通过j Query的设计绘制地图,并得出我前面的简单例子,但我的产出是用<代码>alert($“#foo”)K();陷于尾声。 基本上,我只是精炼的法典,没有利用上文所显示的令人憎恶的特点。

因此,我的问题是,如果我最终使用图书馆,那么我如何能够以这样的方式制定法规,使关闭的汇编者能够把我的守则简化到自己的共同财产(或比未使用的法典的85kb更有效)? 或者,如果有人想要建立一个小的图书馆,哪里设计什么?

问题回答

AFAIK, jQuery is not (yet) written to be optimized by the Closure Compiler s Advanced Mode. It has an "externs" file which will enable its public properties and classes not to be renamed, but it does not enable most of the optimizations (e.g. dead code removal) as you ve discovered. Which is quite a pity, because the jQuery object, if property written, does lends itself quite readily and nicely to the Closure Compiler s prototype virtualization feature.

Slightly off-topic

如果你不与酒吧挂钩,请<>>>>>>>>考虑“Dojo Toolkit”,“m>can

See .this document for details.

j Qu pain pain min min min min min min itself itself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . op op . . op op . . 。

关闭图书馆是一家图书馆的一个实例,该图书馆是为妥善利用关闭汇编而撰写的。

一般来说,汇编者最好采用传统的继承和简单结构:

/** @constructor */ function Class () {} Class.prototype.f = function() {};

With an explicitly exported interface: window[ MyLib ] = { method , method };

一般说来,如果图书馆与内部法典的数量相比,外部接口很小,那么先进模式才对图书馆具有意义。 然而,我肯定会鼓励编写你的图书馆,以便通过一个先进模式的汇编项目来消耗它(这就要求将它作为独立的图书馆使用时所使用的出口分开,如果它们图书馆本身使用先进模式进行排雷)。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.