MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Proxy & Reflect API Deep Dive0%
Study Materials
JavaScript for AdvancedProgress 0%
1.1Higher-Order Functions & Currying1.2Function Composition & Pipelining1.3Memoization & Pure Functions1.4Execution Context & Call Stack Deep Dive1.5Scope Chain & Lexical Environment
17.1Proxy & Reflect API Deep Dive17.2Metaprogramming in JavaScript17.3Functional Programming (Currying, Monads, Functors)17.4Asynchronous Iterators & Reactive Streams
HomeTutorialsJavaScript for AdvancedProxy & Reflect API Deep Dive
Metaprogramming in JavaScript

Proxy & Reflect API Deep Dive

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study Materials

Introduced in ECMAScript 2015 (ES6), the Proxy and Reflect APIs provide low-level metaprogramming capabilities in JavaScript. While standard objects only allow reading and writing properties, Proxy enables wrapping an object to intercept and redefine 13 fundamental language operations (termed Traps).


1. The 13 Proxy Traps and Their Reflect Equivalents

Every trap in a Proxy handler mirrors a corresponding static method on the built-in Reflect object:

Proxy TrapInterceptsTriggered ByReflect Method
getProperty accessobj.prop, obj['prop']Reflect.get()
setProperty assignmentobj.prop = valReflect.set()
hasThe in operator'prop' in objReflect.has()
deletePropertyDeleting a propertydelete obj.propReflect.deleteProperty()
applyFunction callfn(...args), fn.apply()Reflect.apply()
constructThe new operatornew MyClass()Reflect.construct()
getPrototypeOfGetting prototypeObject.getPrototypeOf()Reflect.getPrototypeOf()
setPrototypeOfSetting prototypeObject.setPrototypeOf()Reflect.setPrototypeOf()
isExtensibleExtensibility checkObject.isExtensible()Reflect.isExtensible()
preventExtensionsDisabling extensionsObject.preventExtensions()Reflect.preventExtensions()
getOwnPropertyDescriptorInspecting descriptorsObject.getOwnPropertyDescriptor()Reflect.getOwnPropertyDescriptor()
definePropertyDefining descriptorsObject.defineProperty()Reflect.defineProperty()
ownKeysEnumerating keysObject.keys(), Object.getOwnPropertyNames()Reflect.ownKeys()

2. Why Reflect is Mandatory Inside Proxy Traps

A common beginner mistake is directly calling target[prop] inside a get trap:

1// ANTI-PATTERN: Breaks inheritance when prototype objects access getters!
2get(target, prop) {
3 return target[prop]; // 'this' inside getters will point to target, NOT receiver!
4}
5 
6// CORRECT STANDARD PATTERN:
7get(target, prop, receiver) {
8 return Reflect.get(target, prop, receiver); // Correctly binds 'this' to the Proxy!
9}

The receiver parameter guarantees that if a property is a getter that uses this, this correctly points to the Proxy instance, not the underlying raw target object!


3. Real-World Architectural Implementations

1. Reactive Data Binding (Vue 3 Reactivity Engine)

1function reactive(target, onChange) {
2 return new Proxy(target, {
3 set(target, prop, value, receiver) {
4 const oldValue = target[prop];
5 const result = Reflect.set(target, prop, value, receiver);
6 
7 if (oldValue !== value) {
8 onChange(prop, value, oldValue); // Notify UI to re-render!
9 }
10 return result;
11 }
12 });
13}
14 
15const state = reactive({ count: 0 }, (prop, val) => {
16 console.log(`[Reactivity] Property "${prop}" changed to: ${val}`);
17});
18 
19state.count = 1; // Logs: [Reactivity] Property "count" changed to: 1

2. Negative Array Indexing (Python-Style Arrays)

In JavaScript, arr[-1] returns undefined. We can implement Python-style negative indices using Proxy:

1function createSmartArray(...items) {
2 return new Proxy(items, {
3 get(target, prop, receiver) {
4 if (typeof prop === 'string') {
5 const index = Number(prop);
6 if (!isNaN(index) && index < 0) {
7 // Translate -1 to (length - 1)
8 const resolvedIndex = target.length + index;
9 return Reflect.get(target, resolvedIndex, receiver);
10 }
11 }
12 return Reflect.get(target, prop, receiver);
13 }
14 });
15}
16 
17const list = createSmartArray('A', 'B', 'C', 'D');
18console.log(list[-1]); // 'D' (Last element!)
19console.log(list[-2]); // 'C'

4. Revocable Proxies (Proxy.revocable())

A Revocable Proxy creates a proxy that can be completely disconnected and disabled at any time, instantly cutting off access:

1const sensitiveData = { apiKey: 'SECRET_4920' };
2const { proxy, revoke } = Proxy.revocable(sensitiveData, {});
3 
4console.log(proxy.apiKey); // 'SECRET_4920'
5 
6// Revoke access when session ends:
7revoke();
8 
9// Subsequent access throws TypeError!
10// console.log(proxy.apiKey); // TypeError: Cannot perform 'get' on a proxy that has been revoked!

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How many fundamental internal operation traps can be intercepted by a JavaScript Proxy?
Question 2
Why is the receiver argument passed to Reflect.get(target, prop, receiver)?
Question 3
What happens when code attempts to access a property on a revoked Proxy (created via Proxy.revocable())?
Question 4
Which Proxy trap intercepts the "in" operator (e.g. 'prop' in obj)?
Question 5
What modern frontend framework uses JavaScript Proxies as the core foundation of its fine-grained reactivity system?
Next Lesson

Metaprogramming in JavaScript

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Crash Reporting & Telemetry BufferingMetaprogramming in JavaScript

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Advanced with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext