-->

Reference Error: Proxy is Not Defined

2019-08-05 09:10发布

问题:

I am trying to use ES6 Proxies in an Angular app of mine as so:

// Create defensive object using ES6 Proxy
createDefensiveObject(target) {

  return new Proxy(target, {

    get : (target, property) => {

      if(property in target) 
        return target[property];

      else
        throw new ReferenceError(`Property \"${property}\" does not exist`);
    }
  });
}

I am using Traceur to transpile everything in Chrome, and I have experimental JavaScript enabled. All other ES6 features I have implemented are working as expected, but with Proxies I get : Reference Error: Proxy is not defined

Any insight?

回答1:

Referencing this table here it would seem that Traceur has no support for ES6 proxies at this time. Babel which I use to transpile back-end code also has no support. It looks as though io.js has limited support, so further research will have to be done in order to determine whether that solution will be suitable to our needs. Though this won't help my Angular front-end.