JavaScript 프로토 타입 상속에서 prototype.constructor 속성을 추가하는 목표는 무엇입니까? 예를 들어 설명하겠습니다. Sub.prototype.constructor = 서브를 추가하거나하지 않을 경우 "프로토 타입"의 "constructor"속성 설정의 이점
var Super = function() { this.superProperty = 'Super Property' } var Sub = function() { this.subProperty = 'Sub Property' } Sub.prototype = new Super(); Sub.prototype.constructor = Sub; // advantages of the statement var inst = new Sub();
다음 줄
모든 경우에 항상 true를 돌려줍니다.console.log(inst instanceof Sub) // true console.log(inst instanceof Super) // true
새로운 인스턴스를 가져올 때 유용 할 수도 있지만 언제 어떻게 될 수 있습니까?
미리 감사드립니다.
대단한 질문입니다. – tybro0103