The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Use ES6 Proxies

Use ES6 Proxies

1:32
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.
Watch this lesson now
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?