Skip to main content

Questions tagged [es6-proxy]

The ES2015 Proxy object allows the creation of objects with custom dispatch semantics for operations like property lookup, assignment, enumeration, invocation as a function or constructor.

16 votes
2 answers
10k views

Why is Proxy to a Map object in ES2015 not working

I'm running the following script through Google Chrome Version 57.0.2987.133: var loggingProxyHandler = { "get" : function(targetObj, propName, receiverProxy) { let ret = Reflect....
Rand's user avatar
  • 161
80 votes
5 answers
33k views

How to use javascript proxy for nested objects

I have this code in js bin: var validator = { set (target, key, value) { console.log(target); console.log(key); console.log(value); if(isObject(target[key])){ } return ...
Aflred's user avatar
  • 4,575
100 votes
15 answers
37k views

How to test if an object is a Proxy?

I would like to test if a JavaScript object is a Proxy. The trivial approach if (obj instanceof Proxy) ... doesn't work here, nor does traversing the prototype chain for Proxy.prototype, since all ...
GOTO 0's user avatar
  • 46k
85 votes
13 answers
81k views

How to get the target of a JavaScript Proxy?

How to access the target (which is myArray) of myProxy here? function createProxy() { const myArray = [Math.random(), Math.random()]; return new Proxy(myArray, {}); } const myProxy = createProxy()...
Adam's user avatar
  • 5,173
12 votes
1 answer
2k views

Why is Set Incompatible with Proxy?

JavaScript Set appears to be entirely incompatible with JavaScript proxies, attempting to Proxy() a Set() var p = new Proxy(new Set(), { add(target, val, receiver) { console.log('in add: ', ...
user3467349's user avatar
  • 3,141
59 votes
7 answers
21k views

Can I extend Proxy with an ES2015 class?

I tried to extend Proxy, like so: class ObservableObject extends Proxy {} I used Babel to transpile it to ES5, and I got this error in the browser: app.js:15 Uncaught TypeError: Object prototype may ...
John L.'s user avatar
  • 2,023
0 votes
1 answer
522 views

Weird issue about JavaScript Proxy and getter functions

The two test cases blow both pass. I simply don't understand the behavior. It seems that JavaScript Proxy cannot trap property getting inside a getter function. test('JS Proxy normal method', () => ...
Tyler Liu's user avatar
  • 20.1k
34 votes
5 answers
57k views

Vue Array converted to Proxy object

I'm new to Vue. While making this component I got stuck here. I'm making an AJAX request to an API that returns an array using this code: import axios from 'axios'; export default { data() { ...
Eduardo Robles's user avatar
23 votes
3 answers
15k views

Can Babel transpile code using Proxy into ES5?

I'm using babelify version 6.3.0 set to stage 0. ES6 / ES7 are working great. However when I try to use JavaScript's proxy functionality: set product(product={}) { this._product = new Proxy({}, {})...
Allyl Isocyanate's user avatar
17 votes
3 answers
10k views

How to get proxy's handler from proxy object?

For example, if I have this handler/proxy (from the MDN example)... var handler = { get: function(target, name){ return name in target? target[name] : 37; } }; ...
Steve Ladavich's user avatar
37 votes
3 answers
41k views

ES6 Proxy Polyfill for IE11

IE11 does not and will not implement ES2015 Proxy objects. Yet IE11's end of extended support is October 14, 2025. Is there any way to polyfill Proxy objects for IE11? All other browsers support ...
brillout's user avatar
  • 7,741
31 votes
4 answers
10k views

How do I trap arguments to a target method when using a Proxy object?

I'm trying to use Javascript Proxy objects to trap the arguments that are passed to a 'method' of the target that I'm proxying. Please consider this example: var test = { doSomething: function() ...
Decent Dabbler's user avatar
29 votes
2 answers
20k views

How can I modify a constructor so that it return a proxy that prevents adding new properties to the object?

I want user to only set specific properties to an object but as the same time that object should be constructed from custom class. For example var row = new Row({ name : 'John Doe', email : '...
Uday Hiwarale's user avatar
18 votes
5 answers
5k views

Major use cases for ES6 proxies

I recently got to know about ES6 proxies but I don't see a good reason to use it. I mean, everything that one could do with Proxy can be done without it, except if I'm missing something. For example,...
Ademola Adegbuyi's user avatar
10 votes
3 answers
5k views

ES6 proxied class, access private property (Cannot read private member #hidden from an object whose class did not declare it)

Im playing around with proxy objects, classess and private properties. And came across this error message: /home/marc/projects/playground/pipeline/clsss.js:14 this.#hidden = !this.#hidden; ...
Marc's user avatar
  • 3,836

15 30 50 per page