Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 960 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Use ES6 Proxies

1:32 JavaScript lesson by

A JavaScript Proxy allows you to intercept operations performed on objects, arrays, or functions like property lookup, assignment, invocation, property deletion, and more to add custom behavior. In this lesson we look at how to intercept property lookup with the get "trap" that will allow us to get items starting from the end of the array with ease.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

A JavaScript Proxy allows you to intercept operations performed on objects, arrays, or functions like property lookup, assignment, invocation, property deletion, and more to add custom behavior. In this lesson we look at how to intercept property lookup with the get "trap" that will allow us to get items starting from the end of the array with ease.

Avatar
Rolando

Hey, the video finish like this:

const handler = new Proxy(characters, {
    get(target, name) {
        if(name in target){
            return Reflect.get(target, name)
        } else {
            const index = Number(name)
            return Reflect.get(target, target.length + index)
        }
    }
});

but then in the code bellow:

const handler = {
  get(target, name) {
    if (name in target) {
      return Reflect.get(target, name)
    } else {
      const index = Number(name)
      return Reflect.get(target, target.length + index)
    }
  }
}
In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?