The Reflect API
Forward operations with Reflect methods.
The Reflect API is a free JavaScript Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Reflect?
Reflect is a built-in object with methods that perform the default low-level operations on objects: getting, setting, deleting, and more.
Its methods mirror the proxy traps one-to-one, which makes it the ideal partner for writing correct proxies.
Reflect.get
Reflect.get(target, prop) reads a property, the same as target[prop], but as a clean function call.
const obj = { name: 'Ada', age: 36 };
console.log(Reflect.get(obj, 'name'));
console.log(Reflect.get(obj, 'age'));Reflect.set
Reflect.set(target, prop, value) writes a property and returns true or false indicating success, just like a set trap expects.
const obj = {};
const ok = Reflect.set(obj, 'score', 42);
console.log(ok);
console.log(obj.score);Reflect.has and deleteProperty
Reflect.has mirrors the in operator, and Reflect.deleteProperty mirrors delete, both as functions returning booleans.
const obj = { a: 1, b: 2 };
console.log(Reflect.has(obj, 'a'));
console.log(Reflect.deleteProperty(obj, 'b'));
console.log(Reflect.has(obj, 'b'));Reflect.ownKeys
Reflect.ownKeys returns all own property keys, including symbols and non-enumerable ones, more complete than Object.keys.
const obj = { a: 1, b: 2 };
Object.defineProperty(obj, 'hidden', { value: 3, enumerable: false });
console.log(Object.keys(obj));
console.log(Reflect.ownKeys(obj));Forwarding in a Proxy
The real power: inside a trap, call the matching Reflect method to perform the default behavior, then add your custom logic around it.
const proxy = new Proxy({ v: 1 }, {
get(target, prop, receiver) {
console.log('reading ' + prop);
return Reflect.get(target, prop, receiver);
}
});
console.log(proxy.v);Forwarding set Correctly
Using Reflect.set inside a set trap returns the right boolean automatically, so you do not have to remember to return true yourself.
const proxy = new Proxy({}, {
set(target, prop, value, receiver) {
console.log('writing ' + prop);
return Reflect.set(target, prop, value, receiver);
}
});
proxy.x = 10;
console.log(proxy.x);Why the receiver Matters
Passing receiver to Reflect.get and Reflect.set ensures getters and setters run with the correct this, which matters when objects inherit from one another.
const base = { get label() { return 'id-' + this.id; } };
const proxy = new Proxy(base, {
get(target, prop, receiver) {
return Reflect.get(target, prop, receiver);
}
});
const child = Object.create(proxy);
child.id = 7;
console.log(child.label);Reflect.apply
Reflect.apply(fn, thisArg, argsArray) calls a function with a given this and an array of arguments, a cleaner alternative to fn.apply.
function greet(greeting, name) {
return greeting + ', ' + name;
}
console.log(Reflect.apply(greet, null, ['Hello', 'Ada']));Reflect.construct
Reflect.construct(Cls, argsArray) creates an instance, equivalent to new Cls(...args) but with an array of arguments.
class Point {
constructor(x, y) { this.x = x; this.y = y; }
}
const p = Reflect.construct(Point, [3, 4]);
console.log(p.x, p.y);Why Reflect Matters
Reflect gives function-form, predictable versions of object internals and pairs perfectly with proxies: each trap forwards to its matching Reflect method. The result is correct, minimal proxy code. Next you will apply all this to practical use cases.
const audited = new Proxy({ balance: 100 }, {
set(t, p, v, r) {
console.log(p + ': ' + t[p] + ' -> ' + v);
return Reflect.set(t, p, v, r);
}
});
audited.balance = 150;
console.log(audited.balance);Quick Check
Why call Reflect.get(target, prop, receiver) inside a get trap instead of target[prop]?
Recap: The Reflect API
You learned the partner of Proxy:
Reflectprovides function-form default operations:get,set,has,deleteProperty,ownKeys.- Its methods mirror proxy traps one-to-one.
- Forwarding through
Reflectwith thereceiverkeeps inheritance correct. Reflect.applyandReflect.constructcall and instantiate cleanly.
Frequently asked questions
Is the “The Reflect API” lesson free?
Yes — the full text of “The Reflect API” is free to read here on the web, and the JavaScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “The Reflect API”?
Forward operations with Reflect methods. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “The Reflect API” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Creating a Proxy
- get and set Traps
- The Reflect API
- Practical Proxy Use Cases