Reflect
.getPrototypeOf()
정적 메서드는 주어진 객체의 프로토타입을 반환합니다. Object.getPrototypeOf()
와 거의 동일합니다.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
구문
Reflect.getPrototypeOf(target)
매개변수
target
- 프로토타입을 가져올 대상 객체.
반환 값
주어진 객체의 프로토타입. 상속한 속성이 없으면 null
을 반환합니다.
예외
설명
Reflect.getPrototypeOf()
메서드는 주어진 객체의 프로토타입([[Prototype]]
내부 객체의 값 등)을 반환합니다.
예제
Reflect.getPrototypeOf() 사용하기
Reflect.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf(Object.prototype); // null
Reflect.getPrototypeOf(Object.create(null)); // null
Object.getPrototypeOf()와 비교
// 객체에는 동일한 결과
Object.getPrototypeOf({}); // Object.prototype
Reflect.getPrototypeOf({}); // Object.prototype
// ES5에서는 비객체 대상에서 모두 오류
Object.getPrototypeOf('foo'); // Throws TypeError
Reflect.getPrototypeOf('foo'); // Throws TypeError
// ES2015에서는 Reflect만 오류, Object는 객체로 변환
Object.getPrototypeOf('foo'); // String.prototype
Reflect.getPrototypeOf('foo'); // Throws TypeError
// ES2015 Object 동작을 따라하려면 객체 변환과정 필요
Reflect.getPrototypeOf(Object('foo')); // String.prototype
명세
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Reflect.getPrototypeOf' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Reflect.getPrototypeOf' in that specification. |
Living Standard |
브라우저 호환성
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.