Javascript中的双字母变量名称? [英] Two-letter Variable Names in Javascript?

查看:82
本文介绍了Javascript中的双字母变量名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看回答今天的SO问题,变量名称是ua,rv等。而且我想,伙计,人们什么时候才能学会使用全尺寸变量名称,内存不再是问题但是,它是Javascript 所以它必须遇到问题长变量名称甚至会减慢解释速度。

I was looking at an answer to an SO question today where the variable names are ua, rv, etc. And I thought, "Man, when will people learn to use full-size variable names, memory is not a problem any more" but then, it is Javascript so it has to come across the wire and perhaps long variable names even slow down interpretation.

在Javascript过早优化中使用短变量名吗?

Is using short variable names in Javascript premature optimization?

虽然我在这里,是否有任何Rails或PHP库可以动态压缩Javscript,所以我可以在服务器上保留我的Javascript长名称?

While I'm here, are there any libraries for Rails or PHP that will compress Javscript on the fly, so I can keep my Javascript with long names on the server?

推荐答案

在JS中使用短变量名的唯一原因是通过线路保存字节。然而,这样的发展是荒谬的。他们写的JS也没有空格吗?有一些工具可以优化完成的JS。 Crockford's 是最受欢迎的内容之一(尽管它不会缩短变量名称)。 我无法回想起那些混淆/缩短变量名称的人,但它们确实存在并且编写一个并不难。 Google Closure 是一个非常令人印象深刻的JavaScript 编译器,可以解决这个问题:

The only reason to use short variable names in JS is to save bytes over the wire. However, developing like that is ridiculous. Do they write JS without whitespace, too? There are tools which optimize finished JS. Crockford's is one of the most popular (though it does not shorten variable names). I can't recall offhand one that does obfuscate/shorten variable names, but they do exist and it's not that hard to write one, either. Google Closure is a very impressive JavaScript compiler that turns this:

var myFunction = function(arg1, arg2) {
    var foo = getValue(arg2);
    for(var count = 0; count < arg1.length; count++) {
        alert(foo);
    }
};

进入:

function a(b,c){var d=e(c);for(var f=0;f<b.length;f++){alert(d)}}

这篇关于Javascript中的双字母变量名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆