--- title: Reflect.has() slug: Web/JavaScript/Reference/Global_Objects/Reflect/has tags: - ECMAScript 2015 - JavaScript - Method - Reference - Reflect translation_of: Web/JavaScript/Reference/Global_Objects/Reflect/has ---
Reflect.has() 정적 메서드는 in 연산자의 함수판입니다.
Reflect.has(target, propertyKey)
targetpropertyKey객체가 속성을 가지고 있는지 나타내는 {{jsxref("Boolean")}}.
target이 {{jsxref("Object")}}가 아니면 {{jsxref("TypeError")}}.
Reflect.has() 메서드는 객체에 속성이 존재하는지 판별할 수 있습니다. in 연산자처럼 동작합니다.
Reflect.has() 사용하기Reflect.has({x: 0}, 'x'); // true
Reflect.has({x: 0}, 'y'); // false
// 프로토타입 체인에 존재하는 속성도 true 반환
Reflect.has({x: 0}, 'toString');
// .has() 처리기 메서드를 가진 Proxy
obj = new Proxy({}, {
has(t, k) { return k.startsWith('door'); }
});
Reflect.has(obj, 'doorbell'); // true
Reflect.has(obj, 'dormitory'); // false
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('ES2015', '#sec-reflect.has', 'Reflect.has')}} | {{Spec2('ES2015')}} | Initial definition. |
| {{SpecName('ESDraft', '#sec-reflect.has', 'Reflect.has')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Reflect.has")}}
in 연산자