Microsoft Ajax Minifier重命名我的函数名称 [英] Microsoft Ajax Minifier Renames My Function Names

查看:129
本文介绍了Microsoft Ajax Minifier重命名我的函数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery插件,并通过Microsoft Ajax Minifier运行它.我的脚本对我来说效果很好,但是现在我遇到了与此插件有关的问题.问题是该插件使用字符串按其名称调用函数:

I am using a jQuery plugin and running it through the Microsoft Ajax Minifier. My scripts work well for me, but now I am running into an issue with this plugin. The issue is that the plugin calls a function by its name using a string:

var s = (getCachedSortType(table.config.parsers, c) == "text") ? ((order == 0) ? "sortText" : "sortTextDesc") : ((order == 0) ? "sortNumeric" : "sortNumericDesc");

注意"sortNumeric"和"sortNumericDesc".这将调用以下功能:

Note the "sortNumeric" and "sortNumericDesc". This calls these functions:

function sortNumeric(a, b) {
            return a - b;
        }

function sortNumericDesc(a, b) {
            return b - a;
        }

这是调用这些函数的唯一位置,因此IDE VS2010不会认为这些函数是在任何地方调用的...它们是有条件地通过上面的代码进行的.

This is the only location these functions are called so the IDE VS2010 doesn't think that the functions are being called from anywhere... They are conditionally via the code above.

**这是问题**

**Here is the Problem**

最小化时,该函数的字符串名称会保留,但该函数将被删除,因为它不会对其进行引用.

When this gets minified, the string name of the function stays, but the function gets removed because it does not thing its getting referenced.

有什么方法可以调整设置压缩器以使其不执行此操作?

我也看到它更改了函数的名称,所以

I have also seen it change the names of the functions so

function testFunctionName(a,b)

将成为

function a

这也会对我的情况造成问题... 请注意,对于这样的硬代码函数名称,我知道这是不好的代码设计.就像我说的那样,这是我正在使用的插件.我会接受一种解决方案,该解决方案可以直接调用函数而不是按字符串调用,但是我总是不愿意修改插件.

This would also cause a problem for situations like mine... Please note, that I know it is bad code design to hard code function names like this. Like I said it is a plug-in that I am using. I would accept a solution that would call the function out right instead of by string, but I am always hesitant to modify plug-ins.

推荐答案

使用-unused:keep开关保留未使用的功能.自然,这将防止Minifier删除真正未使用的代码.

Use -unused:keep switch to retain unused functions. This, naturally, will prevent minifier from removing really unused code.

使用 -rename开关为这些函数分配永久名称你按名字打电话.

Use -rename switch to assign permanent names to functions that you call by name.

这篇关于Microsoft Ajax Minifier重命名我的函数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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