Questions tagged [es6-proxy]

The ES2015 Proxy wraps another object and provides customisable behaviour for basic operations (such as accessing properties). Use cases include providing default values for undefined properties, validating set actions and customising the way objects are iterated.

The Proxy object is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).

Syntax

var p = new Proxy(target, handler);
243 questions
3
votes
2 answers

Why is my function proxy not being called in Node?

I was using proxy get method fine. Then I tried using it on a function and quickly realized I needed to use the apply method. This simple example is not working. It never enters apply. Node looks to support apply…
Dave Stein
  • 8,653
  • 13
  • 56
  • 104
3
votes
0 answers

How to get plain javascript array from realm object proxy list?

Scenario: For ex, you define a schema in realm-js as: export const businessSchema = { name: 'Business', primaryKey: 'id', properties: { id: 'int', number_of_stores_in_cities: 'int[]', } } You have already created an object of…
RandomEli
  • 1,527
  • 5
  • 30
  • 53
3
votes
2 answers

Is it possible to create a "before writing" Proxy for a Node.JS object?

Given an object like: var box = { number: 20 } I would like to tie a "before writing" Proxy (or equivalent) to it. This proxy would act as a middleware and perform a type-check. For example, after doing box.number = "30" It would verify that typeof…
adelriosantiago
  • 7,762
  • 7
  • 38
  • 71
3
votes
3 answers

Create Proxy for prototype method

I am fumbling for a way to avoid creating a new Proxy for each new object instance. I have 1 prototype, and I want to use just 1 Proxy. That's the goal. If I use a Proxy per instance, I could have thousands and thousands of Proxy objects which hurts…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
3
votes
2 answers

Fluent async api with ES6 proxy javascript

So... I have some methods. Each method returns a promise. myAsyncMethods: { myNavigate () { // Imagine this is returning a webdriverio promise return new Promise(function(resolve){ …
3
votes
1 answer

Trapping class definition via Proxy in ES6

Is it possible to trap extends? Or to trap definitions inside a class? Eg: class B extends A { method1( ) { } static method2( ) { } } Is there any way to trap the events that: B extended A. method1( ) was defined on B.prototype method2( )…
Gubbi
  • 756
  • 1
  • 7
  • 18
3
votes
1 answer

What is the alternative for enumerate() for JavaScript Proxy to trap for ... in

What is the alternative for the enumerate() for JavaScript Proxy to trap for ... in Since enumerate() is deprecated.
faressoft
  • 19,053
  • 44
  • 104
  • 146
3
votes
2 answers

Create dynamic non-configurable properties using Proxy

I want to create dynamic non-configurable properties using Proxy. I tried this: const proxy = new Proxy({}, { getOwnPropertyDescriptor() { return { configurable: false, enumerable: false, }; …
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
2
votes
2 answers

ES6 Proxy to return an iterable array

I need to exercise some code in data mapping functions. For this, I need a proxy that returns an iterable array with one element (itself; an iterable array) when any property is requested. This will activate all loops and property checks in the…
jcalfee314
  • 4,642
  • 8
  • 43
  • 75
2
votes
1 answer

Can a Proxy really provide access to private fields of a class?

I'm reading the documentation here, and it seems to imply that even for private fields, it would be possible to access them via a Proxy. See the blurb that starts with "....To fix this....". But the example given, doesn't work. My code is shown…
2
votes
2 answers

javascript Proxy of function apply trap gives no access to the receiver Proxy

When I have a Proxy the get and set traps both provide access to the underlying target Object as well as the Proxy receiver of the initial access request. This is good, because for some "pseudo properties" of the Proxy that I need, I look up the…
Gunther Schadow
  • 1,490
  • 13
  • 22
2
votes
1 answer

Is there a away to Bind a Proxy object to the ES6 class constructor?

In ES5^ I can create a proxy object and bind it to the other functions constructors, see what I want to do in the example below: function X() { this.x = `${this.anyAttr} it's a trap`; } function Y() { this.y = `${this.anyAttr} do the barrel…
2
votes
1 answer

Remote objects using web sockets

Is there a library which allows me to call remote objects by web sockets? My target is to able to use an object like any other object (set/get properties on it, call methods) but the object would actually be a proxy over web sockets, where the…
Don Box
  • 3,166
  • 3
  • 26
  • 55
2
votes
1 answer

Native Image object proxy in javascript

In a project, I have to load 3rd party websites in WKWebView. I use iOS recommended userscript to do that. I need to tap on src set to new Image().src and change it if required, without even informing the loaded websites. I had faked Image with a…
2
votes
3 answers

Why console.log receiver value in get handler cause an error?

I am learning ES6 Proxy, and try to understand param 'receiver' in a get trap, so I tried to console.log the receiver value. But when run in nodeJS, it causes an error: RangeError: Maximum call stack size exceeded let proxy = new Proxy({}, { …
Marvin Xu
  • 139
  • 7