【问题标题】:Overwrite javascript reserved words on minify bundles Asp.Net覆盖缩小捆绑 Asp.Net 上的 javascript 保留字
【发布时间】:2013-07-23 17:42:43
【问题描述】:

我在 javascript 中有以下代码:

Array.prototype.any = function (test) {
    if (!arguments.length)
        return !!this.length;

    var arguments = Array.prototype.slice.call(arguments, 1);
    var functionTest = typeof test == "function" ? test : function (x) {return x == test;};

    for (var i = 0, len = this.length; i < len; i++)
        if (functionTest.apply(this[i], [this[i]].concat(arguments)))
            return true;

    return false;
};

当我使用 Asp.net bundle 压缩 JS 文件时,保留字“arguments”变成了一个 char 变量,就像一个字母“i”,但是我需要变量参数,因为它存储了函数的参数。

缩小后可以看到如下:

Array.prototype.any=function(n){var i,r,t,u;if(!i.length)return!!this.length;for(i=Array.prototype.slice.call(i,1),r=typeof n=="function"?n:function(t){return t==n},t=0,u=this.length;t<u;t++)if(r.apply(this[t],[this[t]].concat(i)))return!0;return!1}

有人知道我该如何防止这种变化吗?

【问题讨论】:

    标签: asp.net-mvc-4 bundle minify


    【解决方案1】:

    我不认为将参数分配给参数是一个好主意:)

    删除var arguments = Array.prototype.slice.call(arguments, 1); 并将其替换为var args = Array.prototype.slice.call(arguments, 1);

    【讨论】:

    • 谢谢,它解决了我的问题。我不知道,但是当我使用像变量这样的保留字名称时,缩小器也会识别像本地变量这样的保留字并覆盖上下文中的所有保留字,从而导致错误。
    猜你喜欢
    • 2017-12-12
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    相关资源
    最近更新 更多