最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the custom function(p,a,c,k,e,d) used for? - Stack Overflow

programmeradmin21浏览0评论

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.

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){}

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.

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){}
Share Improve this question edited Nov 12, 2019 at 15:49 TylerH 21.1k76 gold badges79 silver badges111 bronze badges asked Jan 29, 2014 at 6:09 NaveenNaveen 8,24817 gold badges83 silver badges184 bronze badges 0
Add a comment  | 

3 Answers 3

Reset to default 30

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)
}
)();

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.

And even harder to debug.

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.

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.

It's a function which decompresses compressed/obfuscated javascript code. Many JS libraries and scripts make use of it.

There are online tools where you can pack and unpack code via the browser, which use the function.

As I have seen that eval(function(p,a,c,k,e,d){}) is used in http://www.indiabix.com which uses it for hiding whole contents when user get download the page and open it . Maybe that is the inner workings of the particular code.

发布评论

评论列表(0)

  1. 暂无评论