Three.js: Internet Explorer์˜ Function.prototype.name ๋ฒ„๊ทธ

์— ๋งŒ๋“  2017๋…„ 09์›” 27์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: mrdoob/three.js

๋ฌธ์ œ์— ๋Œ€ํ•œ ์„ค๋ช…

Aurelia-CLI ํ”„๋กœ์ ํŠธ์—์„œ THREE๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ๋ชจ๋“ˆ๊ณผ RequireJS๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ๋กœ๋“œ๋˜์—ˆ์Œ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. Internet Explorer (IE 11์—์„œ ํ…Œ์ŠคํŠธ ๋จ)๋ฅผ ์ œ์™ธํ•˜๊ณ ๋Š” ๋ชจ๋‘ ์ž˜ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

์ค‘๋‹จ๋˜๋Š” ์ฝ”๋“œ๋Š” /build/three.js ํŒŒ์ผ์˜ ๋‹ค์Œ (๋งจ ์œ„์˜ polyfill ์„น์…˜ 42-57 ํ–‰)์ž…๋‹ˆ๋‹ค.

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 ์ฝ”๋“œ๊ฐ€ ์ž˜ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํ–ฅํ›„ ๋นŒ๋“œ๋ฅผ ์œ„ํ•ด์ด ์ฝ”๋“œ๋ฅผ ๋Œ€์ฒด ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

Three.js ๋ฒ„์ „
  • [] ๊ฐœ๋ฐœ์ž
  • [x] r87
  • [] ...
๋ธŒ๋ผ์šฐ์ €
  • [] ๋ชจ๋‘
  • [] ํฌ๋กฌ
  • [] Firefox
  • [x] Internet Explorer
OS
  • [] ๋ชจ๋‘
  • [] Windows
  • [x] macOS
  • [] Linux
  • [] Android
  • [] iOS

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

if ๋งŒ ๋ณ€๊ฒฝํ•˜๋ฉด ์ถฉ๋ถ„ ํ•จ์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

if ( 'name' in Function.prototype === false ) {

๊ฐˆ ๊ธธ!

๋ชจ๋“  3 ๋Œ“๊ธ€

์ˆ˜ํ‘œ๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ?

if ( 'name' in Function.prototype === false ) {

๋˜๋Š”

if ( Function.prototype.hasOwnProperty( 'name' ) === false ) {

if ๋งŒ ๋ณ€๊ฒฝํ•˜๋ฉด ์ถฉ๋ถ„ ํ•จ์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

if ( 'name' in Function.prototype === false ) {

๊ฐˆ ๊ธธ!

๊ฒฐ์ •๋œ. ๊ฐ์‚ฌ!

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰