// 생성자 함수 SuperType function SuperType() { this.superValue = "Super"; } // SuperType : Prototype에 메서드 정의 SuperType.prototype.getSuperValue = function() { return this.superValue; }; // 생성자 함수 SubType function SubType() { this.subValue = "Sub"; } // 기존 Prototype 연결을 끊고, // SuperType의 Prototype으로부터 객체 생성 하여 연결하여 상속 SubType.prototype = new SuperType(); // new Prototype객체에 메서드 정의 SubType.prototype.getSubValue = function() { return this.subValue; }; // SuperType을 상속받은 SubType Prototype객체로 부터 객체 생성 var instance = new SubType(); document.write("instanceof 연산자 : <br>"); document.write((instance instanceof Object) + "<br>"); // true document.write((instance instanceof SuperType) + "<br>"); // true document.write((instance instanceof SubType) + "<br>"); // true document.write("<br>isPrototypeOf() 메서드 : <br>"); document.write(Object.prototype.isPrototypeOf(instance) + "<br>"); // true document.write(SuperType.prototype.isPrototypeOf(instance) + "<br>"); // true document.write(SubType.prototype.isPrototypeOf(instance) + "<br>"); // true