---
title: "ES6 Reflect API"
description: "Understanding the Reflect object and its methods in ES6. Practical notes and code examples on ES6 Reflect API by Hemanth HM."
url: "https://h3manth.com/scribe/es6-reflect-api/"
canonical_url: "https://h3manth.com/scribe/es6-reflect-api/"
markdown_url: "https://h3manth.com/scribe/blog/es6-reflect-api.md"
publishDate: "2015-01-12T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["javascript","es6"]
word_count: 202
reading_time_minutes: 2
x_markdown_tokens: 499
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# ES6 Reflect API

> Understanding the Reflect object and its methods in ES6. Practical notes and code examples on ES6 Reflect API by Hemanth HM.

ES6's Reflect object is a single ordinary object that contains methods related to the ECMAScript 6 reflection API.

## Key Points

- It's not a function object
- It does not have a `[[Construct]]` internal method (Can't use `new`)
- It does not have a `[[Call]]` internal method (Can't invoke as a function)

## Reflect Methods

- `Reflect.get(target, name, [receiver])`
- `Reflect.set(target, name, value, [receiver])`
- `Reflect.has(target, name)`
- `Reflect.apply(target, receiver, args)`
- `Reflect.construct(target, args)`
- `Reflect.getOwnPropertyDescriptor(target, name)`
- `Reflect.defineProperty(target, name, desc)`
- `Reflect.getPrototypeOf(target)`
- `Reflect.setPrototypeOf(target, newProto)`
- `Reflect.deleteProperty(target, name)`
- `Reflect.enumerate(target)`
- `Reflect.preventExtensions(target)`
- `Reflect.isExtensible(target)`
- `Reflect.ownKeys(target)`

## Why Reflect?

The major difference from `Object` methods is that Reflect methods return meaningful data rather than throwing errors on failure.

### Without Reflect

```javascript
try {
  Object.defineProperty(obj, name, desc);
  // worked
} catch (e) {
  // bombed
}

### With Reflect
javascript
if (Reflect.defineProperty(obj, name, desc)) {
  // worked
} else {
  // bombed
}
```

## Useful Equivalences

- `Reflect.has(obj, name)` is equivalent to `(name in obj)`
- `Reflect.deleteProperty(obj, name)` is equivalent to `delete obj[name]`

Both are first-class functions which makes them more composable!

## Simplifying apply

Instead of:

```javascript
Function.prototype.apply.call(fn, obj, args)
You can use:

```javascript
Reflect.apply(fn, obj, args)
```
