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

ES6 "universal" proxy

I would like to understand why it is not possible to create an "universal" forward proxy with ES6. By "universal" I mean that the proxy target may be any kind of non-primitive value (including function) with the same proxy declaration (constructor +…
Franck Freiburger
  • 26,310
  • 20
  • 70
  • 95
2
votes
0 answers

Subclass ES6 Proxied Class

I want to Subclass a Proxied ES6 Class. It works just fine in Firefox and Chrome, but Safari 10 throws an error: let SuperClass = class { constructor() { console.log('SuperClass constructor') } } let ProxiedSuperClass = new…
phoboslab
  • 41
  • 1
  • 6
2
votes
1 answer

handler.set in ES6 Proxy return value

In this code function report(message) { console.log(message); } function makeLoggable(target) { return new Proxy(target, { get(target, property) { report(`Reading ${property}`); const param = target; return…
Drylozav
  • 183
  • 1
  • 9
2
votes
1 answer

In node.js ES6, is it possible to pass in a type and then instantiate it?

In my project I have several classes that look like this: "use strict"; var exports = module.exports = {}; var SystemsDAO = require('./dao/systems/SystemsDAO.js'); var aop = require('./dbAOPUtils.js'); var Proxy = require('harmony-proxy'); var…
leeand00
  • 25,510
  • 39
  • 140
  • 297
2
votes
1 answer

JavaScript Proxies: set does not trigger when modifying objects in an array

I have an array filled with objects let array_of_objects = [{ id: 1, name: "John" }, { id: 2, name: "Bill" }, { id: 3, name: "Mike" }]; I then create a proxy with a set handler and my array as a target let p = new…
magom001
  • 608
  • 6
  • 16
2
votes
1 answer

How to wrap or proxy another object in JavaScript in Node.js

I'm doing JavaScript in node.js. I'm trying wrap an object not yet constructed, allowing calls to any object function and set/get any object attribute through the wrapper, letting the wrapper pass calls/sets/gets to the object if bound in the…
1
vote
3 answers

How to always apply a method before executing another method via a proxy?

I have the following code where I want to invoke the instance method connect before proceeding with the invocation of every other instance method of the TelegramClient class. How can this be achieved by making use of Proxy. As of now the connect…
1
vote
1 answer

Is there a nicer way to handle isLoading checks in react?

In React we very often load data which is for some time undefined/null or some placeholder value. Now there are many ways to use loading skeletons, but in my project we have the skeletons rather low in the component hierarchy, so the code goes from…
Andreas Herd
  • 1,120
  • 9
  • 14
1
vote
2 answers

How can I detect changes to arbitrary private members with an ES6 proxy in Javascript?

I am working on building a 2D renderer with the Javascript canvas API, and I am trying to improve performance by skipping renders when no changes to the state of any renderable objects have occurred. To this end, I want to build an extensible class…
Banshee
  • 15
  • 5
1
vote
1 answer

For an instance field which is an array value, how does one handle additional tasks whenever the array mutates by e.g. pushing into or splicing it?

The set accessor does not take place whenever one does mutate the Crumbs class property value by e.g pushing into it. I'm trying to create a class property via set syntax which I expect to handle an additional sessionStorage task. But every time,…
Josue Barrios
  • 440
  • 5
  • 10
1
vote
1 answer

Is it possible to get parent property name of nested object in set method of Proxy object?

https://stackoverflow.com/a/41300128 ↑ completely based on this code var validator = { get(target, key) { if (typeof target[key] === 'object' && target[key] !== null) { return new Proxy(target[key], validator) } else { return…
kazon
  • 344
  • 1
  • 4
  • 15
1
vote
0 answers

argument is `undefined` in reflection function call

I have the following functional logic code: const trans = {} trans['toCssClass'] = (someListing) => { // <-- someListing here is undefined console.log(someListing) someListing.a = someListing.a ? 'nonapproved' : '' someListing.d =…
BenGee23
  • 43
  • 6
1
vote
1 answer

Can I extend default javascript function prototype to let some code been executed on every function call?

Lets say there are functions function a(someparams){ console.log('a called') } function b(){ console.log('b called') } ... const c (someParam) => { console.log('c called')} I want to extend default function prototype something…
1
vote
1 answer

Class Reactivity with Proxy does not work as expected in Vue 3

I have a Class with a proxy-based object, the set() method changes another property of the same class, everything works fine if I run the code only in JS/TS. class Form { errors = [] values = {} constructor(values) { this.values = new…
Yung Silva
  • 1,324
  • 4
  • 20
  • 40
1
vote
1 answer

ES6 Proxies for location.pathname changes

Is it possible to use ES6 Proxies to track changes of location.pathname? As far as I know, Proxies can be used for objects, and location.pathname is an object, right? If the answer is yes, can someone help me understand how to achieve this? The only…
Paul Berger
  • 49
  • 1
  • 6