0

I am using less.js on my local env. I have an issue with IE8 + less.js (1.4.1) + es5-shim.js. When I include es5-shim native ie8 crashes. I checked and did some test that it is because of usage string.trim() function in less.js. When I modified trim function to return not trimmed string ie8 doesn't crash but now script doesn't recognize mixins etc. Maybe anyone has some solution for it?

4

1 回答 1

1

如果您使用 es5-shim 的唯一目的是修剪 polyfill,您可以尝试不使用 es5-shim 并包含此替代 polyfill 并查看它是否有效

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

也就是说,我目前正在使用 es5-shim 版本ES-5 15.5.4.20String.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, "");
    };
}
于 2013-09-25T16:09:27.363 回答