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.

0 votes
0 answers
26 views

I am trying to work with ES6 Proxies but am noticing something super weird, it is getting called twice [closed]

I am trying to implement a simple backbone model which has handlers for change and delete events on the model. The change handler for changing the value of a property gets executed 2 times instead of ...
0 votes
1 answer
279 views

Can't redirect target of freeze operation via preventExtensions trap

Code: (function () { "use strict"; var proxy; var realTarget; var target; realTarget = {}; target = {}; proxy = new Proxy(target, { isExtensible: ...
0 votes
1 answer
30 views

Multiple Access to two-dimensional array (using setters/getter via Proxy or Object.defineProperty)

I have a two dimensional array that I need to perform read and write action on from various angles. Sometimes I need to get/set a single row (easy of course) and sometimes I need to get/set a single ...
22 votes
3 answers
50k views

how to get an array out of a javascript proxy

I was wondering how to get an array out of a proxy's target value in JavaScript. I have something like this : Proxy : [[target]] : Array // the array I need to extract [[handler]] : Object [[...
0 votes
1 answer
65 views

Detect direct instances in JavaScript

A couple of years ago, I wanted figure how to create a type check for class A that returns true only for objects instantiated by new A(). For this, I wrote the class like this: class A { static #...
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,...
-1 votes
1 answer
95 views

Why is this object a Proxy only when the page field is 1?

Steps to reproduce: Open the reproduction Open the browser console When the project starts it will errors with: Uncaught (in promise) DOMException: Failed to execute 'put' on 'IDBObjectStore': #<...
2 votes
0 answers
161 views

Can a proxy with a non-function target be invoked like a function?

Per my answer to this question, chrome allows you to do the following (chrome 49): class Person { constructor() { this.fn = function(a) { this.a = a; }; return new Proxy(this, { apply: ...
5 votes
1 answer
595 views

What would be a use case for identity-preserving membrane proxies?

When I was reading about ES6 Proxies, it seemed simple enough to understand until I had taken a look at this example. I'm stumped. I don't understand the "wet/dry" terminology that they use, ...
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 : '...
0 votes
1 answer
339 views

Why can’t a proxy trap invoke Function.prototype.apply to construct an ES6 class?

I'm trying to Proxy a ES6 constructor (mostly trying to emulate Python's descriptors for fun and learning): class _Record { constructor(data) { this._data = data; } } const ...
3 votes
1 answer
263 views

How do I intercept sort function within a JS proxy?

I know how to intercept get`set` and such within a proxy using the following code: function get( target, prop, receiver ) { console.log("Intercepted get") return Reflect.get( target, ...
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({}, {})...
0 votes
1 answer
79 views

Why are proxy traps not invoked for instances constructed from a proxied constructor?

I'm trying to register function change via proxies with this code: const handler = { construct(objTarget, args, oldConstructor) { return new objTarget(...args) }, set(target, key, value) { ...
1 vote
1 answer
66 views

JavaScript Proxy not working for opened Window object

I need to Proxy a window object opened with window.open. So far as I understand it (which is not well), the trivial "handler" here should effectively be the identity operation, passing thru ...

15 30 50 per page
1
2 3 4 5
21