Skip to main content
Filter by
Sorted by
Tagged with
104 votes
15 answers
43k views

I would like to test if a JavaScript object is a Proxy. The trivial approach if (obj instanceof Proxy) ... doesn't work here, nor does traversing the prototype chain for Proxy.prototype, since all ...
GOTO 0's user avatar
  • 48.8k
93 votes
13 answers
93k views

How to access the target (which is myArray) of myProxy here? function createProxy() { const myArray = [Math.random(), Math.random()]; return new Proxy(myArray, {}); } const myProxy = createProxy()...
Adam's user avatar
  • 5,293
81 votes
5 answers
36k views

I have this code in js bin: var validator = { set (target, key, value) { console.log(target); console.log(key); console.log(value); if(isObject(target[key])){ } return ...
Aflred's user avatar
  • 4,623
67 votes
7 answers
22k views

I tried to extend Proxy, like so: class ObservableObject extends Proxy {} I used Babel to transpile it to ES5, and I got this error in the browser: app.js:15 Uncaught TypeError: Object prototype may ...
John L.'s user avatar
  • 2,151
44 votes
9 answers
56k views

I'm using a library that turns things into ES6 Proxy objects, and another library that I think is choking because I'm passing it one of these (my code is a travesty, I know), and I couldn't figure out ...
Sigfried's user avatar
  • 3,150
37 votes
3 answers
41k views

IE11 does not and will not implement ES2015 Proxy objects. Yet IE11's end of extended support is October 14, 2025. Is there any way to polyfill Proxy objects for IE11? All other browsers support ...
brillout's user avatar
  • 7,478
35 votes
5 answers
68k views

I'm new to Vue. While making this component I got stuck here. I'm making an AJAX request to an API that returns an array using this code: import axios from 'axios'; export default { data() { ...
Eduardo Robles's user avatar
30 votes
4 answers
11k views

I'm trying to use Javascript Proxy objects to trap the arguments that are passed to a 'method' of the target that I'm proxying. Please consider this example: var test = { doSomething: function() ...
Decent Dabbler's user avatar
29 votes
2 answers
21k views

I want user to only set specific properties to an object but as the same time that object should be constructed from custom class. For example var row = new Row({ name : 'John Doe', email : '...
Uday Hiwarale's user avatar
29 votes
3 answers
37k views

I'm shuffling an array and getting a weird message in the console. My JSON file looks like this: [ { "id": 1, "name": "Sushi", "image": "...
Raccoon's user avatar
  • 1,445
28 votes
3 answers
11k views

I'm wrapping an object in a Proxy and then iterate through it. How can I control the keys it iterates through? The proxy works if I don't override the keys: var obj = {"hello": "world"} var proxy =...
Matt Zeunert's user avatar
  • 16.6k
25 votes
3 answers
65k views

I was wondering how to get an array out of a proxy's target value in JavaScript. I have something like this : Proxy : [[target]] : Array // the array I need to extract [[handler]] : Object [[...
Jip Helsen's user avatar
  • 1,386
23 votes
3 answers
15k views

I'm using babelify version 6.3.0 set to stage 0. ES6 / ES7 are working great. However when I try to use JavaScript's proxy functionality: set product(product={}) { this._product = new Proxy({}, {})...
Allyl Isocyanate's user avatar
23 votes
5 answers
6k views

I recently got to know about ES6 proxies but I don't see a good reason to use it. I mean, everything that one could do with Proxy can be done without it, except if I'm missing something. For example,...
Ademola Adegbuyi's user avatar
20 votes
2 answers
6k views

Is there any significant difference between Reflect and Proxy? From what is documented, it seems that they have pretty much the same capabilities, apart from: Reflect being capable of specifying only ...
halfzebra's user avatar
  • 6,815
19 votes
2 answers
4k views

I have the following proxy: const p = new Proxy({}, { ownKeys(target) { return ['a', 'b']; }, }); MDN says that: This trap can intercept these operations: Object.getOwnPropertyNames(...
Michał Perłakowski's user avatar
18 votes
2 answers
11k views

I'm running the following script through Google Chrome Version 57.0.2987.133: var loggingProxyHandler = { "get" : function(targetObj, propName, receiverProxy) { let ret = Reflect....
Rand's user avatar
  • 181
17 votes
3 answers
11k views

For example, if I have this handler/proxy (from the MDN example)... var handler = { get: function(target, name){ return name in target? target[name] : 37; } }; ...
Steve Ladavich's user avatar
17 votes
1 answer
4k views

I want to build a proxy that detects changes to an object: New properties are defined. Existing properties are changed. Code Sample 1 - defineProperty const me = { name: "Matt" } const ...
Matthew Layton's user avatar
17 votes
4 answers
3k views

I made the following class to 'hijack' the console.log function. The reason behind this is that I want to add and remove values dynamically. It will be used for debug purposes, so the origin of the ...
therebelcoder's user avatar
17 votes
1 answer
6k views

What is the correct way to build Javascript proxies for arrays so that 'set' handlers do not get invoked multiple times for a single change to the array? Here is what I mean: I want to wrap a simple ...
TColbert's user avatar
  • 321
17 votes
1 answer
3k views

class A extends HTMLElement { constructor() { super() return new Proxy(this, {}) } } window.customElements.define('a-element', A) <a-element></a-element> How can ...
Артур Лаврищев's user avatar
14 votes
1 answer
2k views

JavaScript Set appears to be entirely incompatible with JavaScript proxies, attempting to Proxy() a Set() var p = new Proxy(new Set(), { add(target, val, receiver) { console.log('in add: ', ...
user3467349's user avatar
  • 3,221
12 votes
3 answers
1k views

I have a simple ES6 class, like so: class Ring extends Array { insert (item, index) { this.splice(index, 0, item); return this; } } I want to make it so that the indexing for ...
ETHproductions's user avatar
12 votes
3 answers
5k views

Im playing around with proxy objects, classess and private properties. And came across this error message: /home/marc/projects/playground/pipeline/clsss.js:14 this.#hidden = !this.#hidden; ...
Marc's user avatar
  • 4,049
11 votes
3 answers
13k views

Say I have a proxy instance like so: const getProxy = function(){ return new Proxy({}, ...); } const proxy = getProxy(); later on, I want to retrieve the target from the proxy, is there some way ...
Alexander Mills's user avatar
11 votes
2 answers
12k views

I have an abstract class: abstract class Foo { abstract bar(): string; } I have some classes that extend Foo: class Foo1 extends Foo { bar(): string { return 'foo1'; } } class Foo2 extends ...
trey-jones's user avatar
  • 3,467
11 votes
2 answers
5k views

I am trying to call .toString() on a function proxy. Simply creating a function proxy and calling toString causes "TypeError: Function.prototype.toString is not generic", setting the toString to ...
Daniel Herr's user avatar
  • 20.7k
10 votes
3 answers
4k views

I am using Proxy to Proxy an object. The getter and setter work fine like expected. However, the apply method is never called. var p = new Proxy({}, { /* getter */ get(target, name) { ...
Jochem Stoel's user avatar
  • 1,391
10 votes
3 answers
6k views

I have the following proxy: const p = new Proxy({ [Symbol.iterator]: Array.prototype.values, forEach: Array.prototype.forEach, }, { get(target, property) { if (property === '0') return 'one'...
Michał Perłakowski's user avatar
10 votes
1 answer
4k views

I have a class that returns a Proxy from the constructor. When I try to store instances of this class in IndexedDB, or send the object using window.postMessage(), I receive an error stating that the ...
dwhieb's user avatar
  • 1,866
9 votes
3 answers
2k views

In the documentation of the Proxy ownKeys trap on MDN it states that it will intercept Object.keys() calls: This trap can intercept these operations: Object.getOwnPropertyNames() Object....
sdgluck's user avatar
  • 27.8k
9 votes
1 answer
1k views

I am compiling the code with babel (env), compiling down to ES5. Here's the code: (async () => { const p = async () => { return new Proxy({}, { get: (...
millsp's user avatar
  • 1,407
9 votes
1 answer
305 views

First of all, I want to clarify, I know that with is deprecated, and using it is generally a bad practice. However, my question is about a special case: using a special Proxy object as the parameter ...
FZs's user avatar
  • 18.8k
8 votes
7 answers
3k views

I am trying to get a hang of ESx (Harmony?) Proxies. I think I know the basics now, but I don't think I'm capable of taking advantage of them. Has anyone managed to use them for any good? I don't ...
Tower's user avatar
  • 103k
8 votes
3 answers
13k views

I am using jest with typescript in my projects. I am getting undefined for all my .ts files using identity-obj-proxy but .js files work as expected. This is my tsconfig.json: { "compilerOptions": {...
Abhishek Raj's user avatar
8 votes
2 answers
3k views

I am trying to make a Proxy object of Image to trap properties but even with an empty handler I get an error message. TypeError: Argument 1 of Node.appendChild does not implement interface Node. The ...
bjanes's user avatar
  • 263
8 votes
4 answers
3k views

Is this even possible? How about other browsers? Any estimates when es6 will be "ready" and rolled out? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy btw. ...
pasuna's user avatar
  • 1,465
8 votes
3 answers
3k views

I want to use Proxy on a customized class called ObservableList which contains an Array. Since Proxy is available only after ES6, I wonder if there is any alternative implementation. My requirement ...
Ovilia's user avatar
  • 7,300
8 votes
2 answers
2k views

I am trying to detect changes in an array of objects using JavaScript proxies. Problem: Any time there is a change in array like deletion or insertion, i want to get that deleted or inserted item. ...
Johar Zaman's user avatar
  • 2,123
7 votes
3 answers
6k views

What's the equivalent of the __call magic method from PHP ? I was under the impression that Proxy can do this, but it can't. class MyClass{ constructor(){ return new Proxy(this, { apply: ...
Alex's user avatar
  • 66.6k
7 votes
2 answers
5k views

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 ...
Siddharth Shyniben's user avatar
7 votes
3 answers
3k views

Using eslint with React configurations I get an error when using Object.defineProperty. The error says: Avoid using Object.defineProperty, instead use Reflect.defineProperty. (prefer-reflect) On the ...
Daniel Reina's user avatar
  • 6,577
7 votes
2 answers
3k views

I can take a Javascript object o and create a new Proxy object from it: let p = new Proxy(object, { ... }) But is there a way to mutate an existing object reference to track changes on the original ...
yawn's user avatar
  • 526
7 votes
1 answer
187 views

TL:DR; Is it possible to make a property of object to be invocable ( as a function ) only ? What i mean by this class Foo{ bar(value){ return value } } let newFoo = new Foo() ...
Code Maniac's user avatar
  • 37.9k
7 votes
1 answer
3k views

When working with JavaScript ES6 Proxies, the set property trap for array.length does not fire when assigning array indexes directly. For example: const proxy = new Proxy([], { set: function(...
kgreen's user avatar
  • 563
6 votes
1 answer
2k views

I want to create a constructor object whose inheritance works as normal, but capture the constructor so I can manipulate the instance object. Using Proxy() almost solves this, but it seems to screw ...
Eric Lange's user avatar
  • 1,793
6 votes
2 answers
4k views

I can not figure out why the following code does not work: var os = new Proxy(require('os'), {}); console.log( os.cpus() ); // TypeError: Illegal invocation whereas var os = require('os'); console....
Franck Freiburger's user avatar
6 votes
3 answers
5k views

I am working with ES6 Proxy. I have created a proxy of an array, now when i check the type of proxy it is giving me as Object type. Question: How can i check if the proxy i have created was for ...
Johar Zaman's user avatar
  • 2,123
6 votes
3 answers
12k views

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,122

1
2 3 4 5
7