自定义函数(p,a,c,k,e,d)用于什么? [英] What is the custom function(p,a,c,k,e,d) used for?

查看:44
本文介绍了自定义函数(p,a,c,k,e,d)用于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多网站的JavaScript代码具有某些功能(p,a,c,k,e,d).不同的网站可能具有不同的功能,但它们都使用相同的参数名称(p,a,c,k,e,d).是标准书还是图书馆书?

I have seen a lot of websites with some function (p,a,c,k,e,d) in their JavaScript code. The different websites may have different bodies of this function, but they all use the same parameter names (p,a,c,k,e,d). Is it a standard or a library or something?

第二,似乎应该在页面加载后立即执行此功能.就像网站上的以下代码段一样.

Secondly, it seems that this function is supposed to be executed as soon as the page loads. Like the following snippet from a website.

您能帮助我理解此代码吗? eval()用于评估诸如 2 + 3 之类的表达式,但是以下代码如何将函数传递给函数呢?

Can you help me in understanding this code? eval() is used to evaluate expressions like 2+3 but how is the following code passing a function to it?

try{
        eval(
            function(p,a,c,k,e,d)
                {
                  //some code goes here
                }
    }catch(err){}

推荐答案

因此,如果您使用 http://matthewfl.com/unPacker.html 就像我在评论中发布的那样,它将代码解压缩"到其中:

So if you use http://matthewfl.com/unPacker.html as I posted in the comments, it "unpacks" the code into this:

(function()
    {
    var b="some sample packed code";
    function something(a)
        {
        alert(a)
    }
    something(b)
}
)();

它似乎不是恶意的.有关为什么要使用此功能的软性争论,请参见 javascript压缩程序与压缩程序:

It doesn't seem to be malicious. For a soft argument on why you would use this, see javascript packer versus minifier:

包装较小,但速度较慢.

Packed is smaller but is slower.

甚至更难调试.

大多数众所周知的框架和插件都只会缩小.


Packer做得更多,然后只是重命名vars和arguments,它实际上映射了使用Base62的源代码,然后必须在客户端上对其进行重建端通过eval()才能使用.

Most of the well known frameworks and plugins are only minified.


Packer does more then just rename vars and arguments, it actually maps the source code using Base62 which then must be rebuilt on the client side via eval() in order to be usable.

在这里,单步执行eval()是一个邪恶的问题,这也会造成启动时页面加载期间客户端上的大量开销包装更大的JS库,例如jQuery.这就是为什么只做缩小建议在您的生产JS上使用JS,因为如果您有足够的代码来需要打包或最小化,您有足够的代码来制作eval()在页面加载期间阻塞客户端.


缩小器仅删除不必要的内容,例如空格字符打包机进一步发展,并尽其所能最小化javascript的大小.例如,它将变量重命名为较小的名字.

Side stepping the eval() is evil issues here, this can also create a large amount of overhead on the client during page load when you start packing larger JS libraries, like jQuery. This why only doing minify on your production JS is recommend, since if you have enough code to need to do packing or minify, you have enough code to make eval() choke the client during page load.


Minifier only removes unnecessary things like white space characters where as a Packer goes one step further and does whatever it can do to minimize the size of javascript. For example it renames variables to smaller names.

这篇关于自定义函数(p,a,c,k,e,d)用于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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