2016-09-20 133 views
0

虽然做了一些跨浏览器测试(在IE8模式下使用IE Edge),但由于Less JS错误导致页面无法正确呈现v2.7.1)。控制台日志:Less.js + IE8 =对象不支持属性或方法'绑定'

SCRIPT438:对象不支持属性或方法 '绑定' 文件:less.js,行:1896年,列:1

同去的缩小的版本 SCRIPT438:对象不支持属性或方法'绑定' File:less.min.js,Line:13,Column:27226

我读过IE8及以下版本不支持bind的问题。

任何人都可以提供一个解决方案,我怎么能解决这个问题,而不必转储少JS完全(不是一个选项)?

+0

见http://lesscss.org/usage/#browser-support,即:“如果你需要在一个较旧的浏览器上运行更少,请使用[ES-5垫片] (https://github.com/kriskowal/es5-shim),它将添加不太需要的javascript功能。“ –

+0

谢谢。会看看。 –

回答

0

您可以使用bind的填充,如MDN's one。正如链接中指出的那样,它与本地网站有一些不同之处。

if (!Function.prototype.bind) { 
    Function.prototype.bind = function(oThis) { 
     if (typeof this !== 'function') { 
     // closest thing possible to the ECMAScript 5 
     // internal IsCallable function 
     throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); 
    } 

    var aArgs = Array.prototype.slice.call(arguments, 1), 
     fToBind = this, 
     fNOP = function() {}, 
     fBound = function() { 
      return fToBind.apply(this instanceof fNOP 
        ? this 
        : oThis, 
        aArgs.concat(Array.prototype.slice.call(arguments))); 
     }; 

    if (this.prototype) { 
     // Function.prototype doesn't have a prototype property 
     fNOP.prototype = this.prototype; 
    } 
    fBound.prototype = new fNOP(); 

    return fBound; 
}; 

}

+0

这是一个简单地将此添加到less.js文件的问题?当谈到JS时,我非常基本,所以不确定这是一个简单的复制>粘贴修复还是需要集成。 –

+0

它必须在使用绑定的代码之前执行。在less.js之前加载的单独脚本将起作用。也许你会需要其他pollyfills功能不支持的IE8。 –

+0

感谢Vincente的帮助。它确实绕过了错误,但现在只显示另一个(SCRIPT438:对象不支持属性或方法'键' - File:less.min.js,Line:10,Column:28054)。我想我会开始寻找替代解决方案。 –

相关问题