I'm using THREE in an Aurelia-CLI project. It means it is loaded using modules and RequireJS. It works all fine except in Internet Explorer (tested in IE 11).
The code that breaks is the following (in the polyfill section at the top, lines 42-57) in the /build/three.js file
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 ];
}
} );
}
It returns the can't redefine non-configurable property "name"
error.
Following this post I've tried to replace the code above with:
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;
}
});
}
And it fixes the problem !
=> It seems that the polyfill code currently used in /build/three.js doesn't work well. Is it possible to replace this code for future builds ?
Would change the check to this make any difference?
if ( 'name' in Function.prototype === false ) {
Or
if ( Function.prototype.hasOwnProperty( 'name' ) === false ) {
I confirm that only changing the if
is enough.
if ( 'name' in Function.prototype === false ) {
it the way to go!
Fixed. Thanks!
Most helpful comment
I confirm that only changing the
if
is enough.it the way to go!