English 中文(简体)
• 我如何获得谷歌关闭汇编,以消除特性
原标题:How can I get Google s Closure Compiler to eliminate attributes

在使用谷歌封闭器时,采用以下代码:

function add(v1, v2){
    return {x: v1.x + v2.x, y: v1.y + v2.y};
}

function lengthSq(vec){
    return vec.x*vec.x+vec.y*vec.y;
}

function test(v11, v12, v21, v22) {
    return lengthSq(add({x:v11, y:v12},{x:v21, y:v22}));
}
window[ func ]=test;

我取得了这一令人不满意的结果:

window.func = function(b, c, a, d) {
  b = {x:b, y:c};
  a = {x:a, y:d};
  a = {x:b.x + a.x, y:b.y + a.y};
  return a.x * a.x + a.y * a.y
};

我希望:

window.func = function(a, b, c, d) {
  return (a+c) * (a+c) + (b+d) * (b+d)
};

这里的真正问题是,我需要储存属性价值,以便我能够从职能中获得多重回报价值。 就我所知,没有其他办法获得多重回返价值。 起初,我曾希望,“结业者”会给我消除这些障碍,但似乎并非如此。

www.un.org/Depts/DGACM/index_spanish.htm 能否有一个实用或面向目标的javascript图书馆,该图书馆可产生相当于最佳范例的产出代码?

我相信,我的业绩测试守则存在缺陷,因为无属性守则在 Chrome和 Firefox上几乎是100倍,在歌剧上是12倍,而在IEE9上是4倍。

performance test of this code: http://jsperf.com/closure-compiler-vs-hand-optimized-vectors

最佳回答

There is a pending change to the compiler under review that attempts to do this: http://code.google.com/p/closure-compiler/issues/detail?id=394

问题回答

暂无回答




相关问题
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.

热门标签