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
-1
votes
2 answers

How to Know if a Proxy call/access is nested?

I'm working with JS Proxies for fun and have made decent progress. But currently it's all at a single level. What I would like is to have nested Proxies be returned if I'm making a nested call/access, otherwise just return the object. // example…
Merlin -they-them-
  • 2,731
  • 3
  • 22
  • 39
-1
votes
1 answer

Why is a Proxy allowed to skip looking up properties in the prototype?

According to the ECMAScript spec, obj.[[Get]] is resolved as follows: First check whether an object has the key (GetOwnProperty) If it does not, defer to [[Get]] of obj’s prototype. […] (other steps omitted) However, the spec for proxy.[[Get]]…
blackening
  • 903
  • 6
  • 14
-4
votes
1 answer

How do I make `foo[1] ==1; foo[1][2]==3; foo[1][2][3]==6` work in JavaScript?

How do I define foo to make the following code work correctly as expected (in JavaScript)? foo[1] + 1 // 2 foo[1][2] + 1 // 4 foo[10][20][30] + 1 // 61 foo[100][200][300] + 1 // 601 This is an interview question I once met.
MurphyChen
  • 57
  • 4
1 2 3
16
17