减去 1.4 string.trim() IE8 崩溃

less 1.4 string.trim() ie8 crash

本文关键字:IE8 崩溃 trim string 减去      更新时间:2023-09-26

我在本地环境上使用的更少.js。我对IE8 + less.js(1.4.1)+ es5-shim.js有问题。当我包括 es5-shim 本机 ie8 崩溃时。我检查并做了一些测试,这是因为在 less.js 中使用 string.trim() 函数。当我修改修剪函数以返回未修剪的字符串 ie8 不会崩溃,但现在脚本无法识别混合蛋白等。也许有人对此有一些解决方案?

如果您唯一使用 es5-shim 的是

修剪填充,您可以尝试不使用 es5-shim 并包含这个备用填充,看看它是否有效

''.trim||(String.prototype.trim=function(){return this.replace(/^['s'uFEFF]+|['s'uFEFF]+$/g,'')});

也就是说,我正在使用当前使用的 es5-shim ES-5 15.5.4.20版本的 String.trim() 和更低版本的 v1.4.2,它们在 IE8 中很好地协同工作。

如果您想比较实现,我正在运行的版本有此代码...

// ES5 15.5.4.20
// http://es5.github.com/#x15.5.4.20
var ws = "'x09'x0A'x0B'x0C'x0D'x20'xA0'u1680'u180E'u2000'u2001'u2002'u2003" +
    "'u2004'u2005'u2006'u2007'u2008'u2009'u200A'u202F'u205F'u3000'u2028" +
    "'u2029'uFEFF";
if (!String.prototype.trim || ws.trim()) {
    // http://blog.stevenlevithan.com/archives/faster-trim-javascript
    // http://perfectionkills.com/whitespace-deviations/
    ws = "[" + ws + "]";
    var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
        trimEndRegexp = new RegExp(ws + ws + "*$");
    String.prototype.trim = function trim() {
        if (this === void 0 || this === null) {
            throw new TypeError("can't convert "+this+" to object");
        }
        return String(this)
            .replace(trimBeginRegexp, "")
            .replace(trimEndRegexp, "");
    };
}