instanceof
가 선호된다. __proto__
은 비표준이며, 특히 Internet Explorer에서는 작동하지 않습니다.
Object.getPrototypeOf(obj)
은 __proto__
과 동일한 기능을하는 ECMAScript 5 기능입니다.
instanceof
은 전체 프로토 타입 체인을 검색하는 반면 getPrototypeOf
은 한 단계 위를 찾습니다.
일부 사용시주의 사항 : __proto__
이 (- it will most likely be standard in ECMAScript 6 아직)없는 동안
new String() instanceof String // true
(new String()).__proto__ == String // false!
// the prototype of String is (new String(""))
Object.getPrototypeOf(new String()) == String // FALSE, same as above
(new String()).__proto__ == String.prototype // true! (if supported)
Object.getPrototypeOf(new String()) == String.prototype // true! (if supported)
다른 메소드가 약간 hackish로 보이고 ECMAScript의 다음 버전 작업을 쉽게 중단 할 수 있기 때문에 instanceof라고합니다. –
많은 도움이되는 훌륭한 기사가 있습니다. [http://ejohn.org/blog/objectgetprototypeof/](http://ejohn.org/blog/objectgetprototypeof/) – Ramin