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 ...
anipendakur's user avatar
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 ...
Christian Schäfer's user avatar
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 #...
Melab's user avatar
  • 2,704
-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': #<...
Fred Hors's user avatar
  • 3,805
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 ...
Boann's user avatar
  • 49.5k
0 votes
1 answer
33 views

Mocking an async builder pattern API with proxy

I'm trying to mock knex for testing. Everything seems to work but attaching a proxy to an array as prototype seems to remove the iteratability of arrays. Here is the mock function. Following works ...
srinesha's user avatar
0 votes
1 answer
74 views

Cannot access puppeteer Proxy in my Jest test (TypeError: Cannot read private member #frameManager from an object whose class did not declare it)

What could be the reason of me not being able to access the Proxy of the CustomPage class in my test file? I get this error... enter image description here const puppeteer = require("puppeteer&...
Aleksandregvrm's user avatar
0 votes
1 answer
32 views

Javscript proxy not transparent in Chrome

A common trick sites use to protect against reverse engineering is to prevent Javascript from executing correctly when the developer tools are open. Usually, this relies on an object logged to the ...
user2248702's user avatar
  • 2,948
0 votes
0 answers
77 views

Trap array changes (add/delete) inside object of proxy

I am trying to track some array changes inside of proxyfied object. For example: object = { count: 0, input: ``, tasks: [ ] } and I need to track changes of object.tasks. The problem ...
Eugene S's user avatar
0 votes
1 answer
81 views

Debounce "setting" of values in proxy trap without delay/timeout

I try to understand how i can debounce a "set" trap in javascript proxy. function debounce(func, wait, immediate = false) { let timeout = null; return function(...args) { let ...
Marc's user avatar
  • 3,836
1 vote
2 answers
96 views

Can a Proxy detect that a subclass is adding methods to a class?

Given a class like: class A {} Is it possible to modify in any way so that I can proxy when methods are subclassed like so: // proxy the `A` object in some way const handler = { get(target, ...
vixalien's user avatar
  • 370
0 votes
0 answers
52 views

How to attach toString to proxy handler

Consider this code: handler.toString = function() { return Reflect.get(original,'toString'); } handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){ try { ...
MD Luffy's user avatar
  • 546
-3 votes
1 answer
175 views

How can I use proxy with spread operator or object.assign?

I need to have methods and store bound to 'this' in my callback function, but when I use the spread operator it doesn't work. The reason for this as far as I know is that the spread operator returns a ...
EMILO's user avatar
  • 433
0 votes
1 answer
76 views

myRef.value is holding a Proxy even tho it should hold a simple array

I am doing a simple app that fetches data (my tasks) from my PocketBase(BaaS like Firebase). I want to store my tasks into a ref because it could change overtime (ex: user modify the name of it). I am ...
santoro's user avatar
  • 13
0 votes
0 answers
62 views

How to globally track property changes and DOM mutations in JavaScript?

I am working on a project where I need to monitor changes in the DOM, specifically tracking any and all JavaScript property changes that affect the DOM elements. My goal is to listen for any 'set' ...
Imperial A's user avatar
1 vote
3 answers
123 views

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 ...
kabdik's user avatar
  • 25
0 votes
0 answers
21 views

Typescript derives different types when a static method is called from inside or outside a class

Can someone help me explain the behavior of typescript in this example. I have no idea what is going on here. Why is childProxy1.foo not resolved while childProxy2.foo is resolved correctly? Why is ...
Micha Stubi's user avatar
1 vote
1 answer
66 views

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

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 ...
Andreas Herd's user avatar
  • 1,188
0 votes
1 answer
64 views

A proxied JS child class assigns a wrong prototype to an instance

Some interesting case which I don't understand. I proxy classes and extend a child class from a proxied base class. When a child is constructed inside the construct trap for some reason a wrong ...
Alexander Nenashev's user avatar
0 votes
0 answers
31 views

How to get data from a Proxy Array in Javascript? [duplicate]

I am making a request via Axios to a REST API made in LARAVEL 9, this is my Backend that sends them via JSON to the frontend. public function index() { try { $marcas = DB::table('marca')-&...
Diego Martinez's user avatar
2 votes
2 answers
519 views

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 ...
jcalfee314's user avatar
  • 4,790
0 votes
2 answers
57 views

JavaScript proxies : aggregate notifications after array sort

I would like to find a way to get only one notification after an array sort Is there a way? Thank you const callback = function () { console.log (...arguments) } const array = [2,1] const handler = {...
tit's user avatar
  • 619
-1 votes
1 answer
52 views

Why is Proxy being called for nested elements?

I'm attempting to abstract some Cypress methods into a helper object using getters. The intended behavior is that I can do something like this: todoApp.todoPage.todoApp.main.rows.row .first()....
user3534080's user avatar
  • 1,405
1 vote
3 answers
75 views

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. ...
Banshee's user avatar
  • 15
0 votes
1 answer
616 views

Typescript: function should return proxy object of generic object type

The following function should create a proxy object with a specific handler, but typescript is throwing a type error when I try it that way. function createProxiedObject<T extends object>(obj: T)...
Arber's user avatar
  • 521
-1 votes
1 answer
207 views

Javascript construct trap not working in class returning proxy

I am trying to create a little javascript two way form binder using proxies. I am stuck on how I can intercept 'new' calls. I use a 'construct' trap but it doesn't fire. Here is my code, I have ...
kiwichris's user avatar
  • 355
-1 votes
2 answers
339 views

How to proxy Function.prototype?

I tried to proxy Function.prototype. I created a new Proxy and rewrote the toString method, however console.log('cas') doesn't work, why? Function.prototype = new Proxy(Function.prototype, { get: ...
yg lin's user avatar
  • 113
1 vote
1 answer
66 views

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 ...
Josue Barrios's user avatar
1 vote
1 answer
279 views

why are target and receiver not the same in this javascript proxy?

I am working with JavaScript Proxy and do not understand why the target and the receiver are different in both the get() and set() traps. They appear to be the same (based on console logging). The ...
bmacnaughton's user avatar
  • 5,198
1 vote
1 answer
233 views

Implement a dynamic lazy proxy collection class on typescript

I'm trying to implement a lazy database connection collection in typescript. I'm creating a class called DatabaseCollection and my idea is to use a proxy to lazy load the connections (I'm using knex ...
Felipe Buccioni's user avatar
0 votes
1 answer
113 views

Value of this inside a Proxy trap

I have the following code: function delay(f, ms) { return new Proxy(f, { apply(target, thisArg, args) { console.log(this) console.log(thisArg) ...
Pavlo Zalutskiy's user avatar
0 votes
0 answers
318 views

JavaScript Error: caught (in promise) TypeError: 'set' on proxy: trap returned falsish for property

I'm attempting to add an "eventlistener" of sorts to trigger when all of the application resources have completed loading. If I understand Proxies correctly, "this is the way" to ...
TK421's user avatar
  • 865
1 vote
1 answer
374 views

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 ...
kazon's user avatar
  • 402
0 votes
1 answer
34 views

How do I roll back the values of the items or collections after an unexpected error?

<q-select v-model="item" :options="colect"> <q-input v-model="item.name"> const colect = ref([... ]) const item = ref({... }) The dilemma is that, when ...
Rafa Calderón's user avatar
0 votes
1 answer
48 views

Why object is not proxied like an argument in function

i have an interesting example of code that's not working like i'm expected. I really dont understand why my obj wouldnt proxy. I'm expect that obj ill proxy via link, but it's not. Can anyone explain ...
user469485's user avatar
0 votes
1 answer
840 views

TypeScript types for Proxy with dynamic properties

I want to type a JavaScript Proxy that allows access to arbitrary properties. A contrived example, an object that maps every property to it's own property name: const proxy = new Proxy({}, {   get(...
tlrobinson's user avatar
  • 2,838
5 votes
3 answers
7k views

'get' on proxy: property 'items' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value

What does this JavaScript error actually mean? I'm not asking about my specific case, just generally how is this error message meant to be understood? TypeError: 'get' on proxy: property 'items' is a ...
Fabis's user avatar
  • 2,052
0 votes
0 answers
18 views

React - Use JavaScript Proxy Object to update with Custom Hook [duplicate]

I am seeing a weird behavior with a simple custom React Hook I am trying to come up with. Any ideas on why it's not working as intended would be greatly appreciated. So I have a custom hook called ...
Hunter Woodall's user avatar
1 vote
0 answers
26 views

argument is `undefined` in reflection function call [duplicate]

I have the following functional logic code: const trans = {} trans['toCssClass'] = (someListing) => { // <-- someListing here is undefined console.log(someListing) someListing.a = ...
BenGee23's user avatar
0 votes
0 answers
175 views

How to Proxy Built-In JS Object?

I want to proxy some built in object primitives in JS, for example, “Number” or “String” object wrappers. However it seems the Proxy object ends up reporting as a normal JS object when passed to some ...
joehinkle11's user avatar
1 vote
0 answers
1k views

Javascript Proxy Object in React Custom Hook

I have 2 custom hooks useFormInput and other useFormInputWithoutProxies which is using Javascript proxy My Question what benefit does Javascript proxy provides over creating normal custom hooks ? Can ...
Sachin 's user avatar
  • 191
0 votes
0 answers
1k views

property 'prototype' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value

I want interception object with proxy,but I can’t understand why I report an error function createReactiveObject(target) { if (!isObject(target)) { return target; } return ...
magician wang's user avatar
1 vote
1 answer
119 views

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 ...
Maria's user avatar
  • 13
1 vote
1 answer
827 views

Javascript proxy for nested object (apply for all function calls)

I'm looking for away to use a proxy on a nested object. In this example I would like to add 1 in my proxy for the result of every function call in that object. How would I go about this, since I can't ...
Jan Schmutz's user avatar
0 votes
1 answer
123 views

How to make a web component return a Proxy (and be extended)

The goal is to have a base class A extending HTMLElement that customizes getters and setters. Then class B would extend class A and do stuff. The way to do this is by wrapping class A with a proxy (...
daniel p's user avatar
  • 939
3 votes
1 answer
2k views

How can I reliably convert a proxy to a standard object?

I'm working with events in JavaScript, and often the event is a proxy object. When debugging I can usually use this to get a copy of the object. console.log(JSON.parse(JSON.stringify(event.detail))); ...
Chuck's user avatar
  • 4,800
1 vote
1 answer
490 views

Why is `this` undefined in a constructor defined Proxy method for a derived class?

I attempting to overwrite/proxy a function from a library class. I've done this by extending the class and defining a Proxy object over the method. Alas, like in this question, the this object in the ...
Lee's user avatar
  • 30.6k
1 vote
0 answers
275 views

Proxy js object: where are defined arguments when calling a function using Reflect.get()

Trying to understand the internals of Proxy and Reflect built-in objects, I've reached - IMO - an interesting "how does this even work" point: Let's say I want to wrap into a Proxy this ...
Manu Artero's user avatar
  • 10.1k
-1 votes
2 answers
4k views

Get array in [[target]] from proxy

How can i get this number from productCount.value (screenshot)? Trying productCount.value.array, but i will get again proxy - [[target]] - array Edit 1: If i use productCount.value.array[0] i will get ...
Jessika's user avatar
  • 27
1 vote
0 answers
63 views

IntersectionObserver superseded by Proxy?

It makes sense to me that IntersectionObserver is preferred to adding scroll-based event listeners these days. Great. However, I read here and here that a Proxy offers a more desirable way to do this ...
ACJ's user avatar
  • 13

15 30 50 per page
1
2 3 4 5
7