我在 Aurelia-CLI 项目中使用了三个。 这意味着它是使用模块和 RequireJS 加载的。 除了在 Internet Explorer 中(在 IE 11 中测试)之外,它一切正常。
中断的代码如下(在顶部的 polyfill 部分,第 42-57 行)在/build/three.js文件中
if ( Function.prototype.name === undefined ) {
// Missing in IE
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
Object.defineProperty( Function.prototype, 'name', {
get: function () {
return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
}
} );
}
它返回can't redefine non-configurable property "name"
错误。
在这篇文章之后,我尝试将上面的代码替换为:
if (!(function f() {}).name) {
Object.defineProperty(Function.prototype, 'name', {
get: function() {
var name = (this.toString().match(/^function\s*([^\s(]+)/) || [])[1];
// For better performance only parse once, and then cache the
// result through a new accessor for repeated access.
Object.defineProperty(this, 'name', { value: name });
return name;
}
});
}
它解决了这个问题!
=> 目前在 /build/three.js 中使用的 polyfill 代码似乎不能很好地工作。 是否可以为将来的构建替换此代码?
将支票改成这样会有什么不同吗?
if ( 'name' in Function.prototype === false ) {
或者
if ( Function.prototype.hasOwnProperty( 'name' ) === false ) {
我确认只更改if
就足够了。
if ( 'name' in Function.prototype === false ) {
这是要走的路!
固定的。 谢谢!
最有用的评论
我确认只更改
if
就足够了。这是要走的路!