• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

__proto__가 deprecated된 이유

21.12.03 15:59 작성 조회수 518

1

__proto__가 deprecated된 이유를 찾는 중에  예전에 답변하신 글을 보고 궁금해서 질문 드립니다.

1. 이전까지는 비표준이였다가 기존의 호환성을 우려해서 어쩔수없이 ES6에서 표준으로 지정하였다면 계속 사용하면 될텐데 deprecated 이유가 어떤 것들이 있나요?

2. MDN에서의 글을 읽어보니 그 이유 중 하나는 성능과 관련있다는 것 같은데 이에 대해서도 알고 싶습니다.

 

답변 3

·

답변을 작성해보세요.

8

1

MDN을 읽어보셨다니 제가 그보다 더 깊이 있는 답변을 드리긴 어려울 것 같습니다.
저는 일개 직장인 개발자일 뿐이라서, 브라우저 및 TC39 위원회 분들의 의도를 충분히 파악할 수가 없네요^^a
아쉬운 마음을 전하며, 대신이라기엔 뭐하지만 MDN 문서상의 내용들을 다시 한 번 같이 확인해보도록 하지요.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible. Be aware that this feature may cease to work at any time.

번역) 이 기능은 더 이상 권장되지 않습니다. 일부 브라우저는 여전히 이를 지원할 수 있지만 관련 웹 표준에서 이미 제거되었거나 삭제 과정에 있거나 호환성 목적으로만 유지될 수 있습니다. 사용을 피하고 가능하면 기존 코드를 업데이트하십시오. 이 기능은 언제든지 작동을 중지할 수 있습니다.

 

Warning: Changing the [[Prototype]] of an object is, by the nature of how modern JavaScript engines optimize property accesses, a very slow operation, in every browser and JavaScript engine. The effects on the performance of altering inheritance are subtle and far-flung, and are not limited to the time spent in obj.__proto__ = ... statements, but may extend to any code that has access to any object whose [[Prototype]] has been altered. If you care about performance you should avoid setting the [[Prototype]] of an object. Instead, create a new object with the desired [[Prototype]] using Object.create().

번역) 객체의 [[Prototype]]을 변경하는 것은 "최신 JavaScript 엔진이 속성 액세스를 최적화하는 방식"의 특성에 따라, 모든 브라우저 및 JavaScript 엔진에서 매우 느린 작업입니다. 상속 구조를 변경하는 것이 성능에 미치는 영향은 미묘하고 광범위하며, obj.__proto__ = ... 문에 소요된 시간에 국한되지 않고 [[Prototype]]이 변경된 객체에 접근할 수 있는 모든 코드로 확장될 수 있습니다. 성능에 관심이 있다면 객체의 [[Prototype]] 설정을 피해야 합니다. 대신 Object.create()를 사용하여 원하는 [[Prototype]]으로 새 객체를 만듭니다.

=> 추측) obj.__proto__ = ... 문을 자바스크립트 엔진이 처리할 때, [[Prototype]]이 변경된 객체에 접근할 수 있는 모든 코드에 대해서 일괄적으로 처리하게 됨에 따라 시간을 상당히 많이 잡아먹을 수도 있다는 내용이 아닐까 싶네요.

 

Warning: While Object.prototype.__proto__ is supported today in most browsers, its existence and exact behavior has only been standardized in the ECMAScript 2015 specification as a legacy feature to ensure compatibility for web browsers. For better support, use Object.getPrototypeOf() instead.

번역) Object.prototype.__proto__는 오늘날 대부분의 브라우저에서 지원되지만 그 존재와 정확한 동작은 웹 브라우저와의 호환성을 보장하기 위해 레거시 기능으로 ECMAScript 2015 사양에서만 표준화되었습니다. 더 나은 지원을 위해 대신 Object.getPrototypeOf()를 사용하십시오.

 

The use of __proto__ is controversial and discouraged. It is deprecated in favor of Object.getPrototypeOf/Reflect.getPrototypeOf and Object.setPrototypeOf/Reflect.setPrototypeOf (though still, setting the [[Prototype]] of an object is a slow operation that should be avoided if performance is a concern).

번역) __proto__의 사용은 논란의 여지가 있으며 권장하지 않습니다.
Object.getPrototypeOf/Reflect.getPrototypeOf 및
Object.setPrototypeOf/Reflect.setPrototypeOf의 사용을 권장하기 위해
__proto__가 deprecated 되었습니다.
(하지만 여전히 개체의 [[Prototype]] 설정은 성능이 문제인 경우 피해야 하는 느린 작업입니다).

0

LEO님의 프로필

LEO

질문자

2021.12.03

그냥 성능상의 문제 때문이라고 파악해두는 것이 최선이군요!!

수고스럽게 번역 및 추측까지 해주셔서 정말 감사합니다. : )