Questions tagged [javascript-proxy]
36 questions
5
votes
2 answers
Only add even numbers to Array using JavaScript Proxy
I'm learning JavaScript Proxy .
By using set trap i only want to add even number to Array. But every time throw
Uncaught TypeError: 'set' on proxy: trap returned falsish for property
'length'
Here is my code example.
//Only even numbers will be…

sahed moral
- 345
- 3
- 13
4
votes
1 answer
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, prop, receiver );
}
var handler = {
'get': get
};
var proxy…

Blue Granny
- 772
- 1
- 8
- 24
3
votes
2 answers
'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 read-only and non-configurable data property on…

Fabis
- 1,932
- 2
- 20
- 37
3
votes
2 answers
Is it possible to Proxy primitives (strings, numbers)?
I'm exploring Proxies in JavaScript, and I want to know if there are any ways to Proxy primitives. If I try to do so:
new Proxy('I am a string');
It throws Uncaught TypeError: `target` argument of Proxy must be an object, got the string "I am a…

Siddharth Shyniben
- 572
- 4
- 18
3
votes
0 answers
Proxying localStorage for dynamic object insertion
I want to proxy localStorage setters and getters to parse objects and save them to storage on assignment like I use a regular object.
Pretty straight forward when saving single KV items but complicated(for me) when trying to update a nested object…

Vadim Brook
- 63
- 7
2
votes
1 answer
Why does Proxy break this-binding?
I'm trying to proxy a set of object such that I can pass them off to third party code and temporarily nullify mutation methods and setters, and then revoke the proxy handler traps to reinstate normal behaviour. What I've discovered is that proxies…

Barney
- 16,181
- 5
- 62
- 76
1
vote
1 answer
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 mozilla docs say that the receiver is either the…

bmacnaughton
- 4,950
- 3
- 27
- 36
1
vote
1 answer
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 as connector) the class works fine in terms of…

Felipe Buccioni
- 19,109
- 2
- 28
- 28
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…

Maria Rodrigez-Gonzales Jr
- 13
- 1
- 2
1
vote
0 answers
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 and that Object.observe is perhaps even…

ACJ
- 13
- 4
1
vote
0 answers
Can I make a Mobx observable with a custom getter?
I have a need for a Mobx observable object which simply returns whichever property is asked of it as a string. For example, myObs.description would simply return the string "description". With a normal JS object, I would use a proxy with a custom…

Nathan
- 185
- 1
- 2
- 10
1
vote
0 answers
Start a browser with a logged proxy in Robot framework
i'm facing the current problem: Since i'm under VPN, when i open a browser, a browser popup appears and ask me for the user and password credentials:
I need to open a browser in robot framework (firefox or chrome is the same) with a logged proxy.
I…

AutomationNeeded
- 53
- 1
- 5
1
vote
1 answer
JavaScirpt - window.console proxy
I'm trying to persist console.log, console.warn...
Is it possible to have a proxy on window.console?
I tried:
new Proxy(window.console, {
get(target, key) {
const p = target[key];
debugger; // Never gets…

user5507535
- 1,580
- 1
- 18
- 39
1
vote
2 answers
JavaScript proxy: Simple log function that will proxy an string argument to the console.log()
I'm new to JavaScript and learning it for a week now. I had applied for an internship in different companies and I was called yesterday for an interview. They asked me some questions and for this one particular question, I had no clue. Can someone…

anish
- 19
- 4
0
votes
0 answers
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 there a difference, when Factory.create() is called…

Micha Stubi
- 1
- 1