Skip to main content

All Questions

Tagged with
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
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
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
2 votes
1 answer
767 views

Is there a away to Bind a Proxy object to the ES6 class constructor?

In ES5^ I can create a proxy object and bind it to the other functions constructors, see what I want to do in the example below: function X() { this.x = `${this.anyAttr} it's a trap`; } ...
Daniel de Andrade Varela's user avatar
2 votes
2 answers
3k views

How to make a getter proxy for all instances of a class in javascript?

Proxies can be used to define 'general getters' for objects. For example var obj = {'a':3, 'b':4 }; var proxy = new Proxy( obj, { get: function(obj, prop){return obj[prop]+10} } ); proxy.a //13 ...
AccidentalTaylorExpansion's user avatar
1 vote
2 answers
1k views

How to extend a class wrapped in a Proxy

I have a complex class that requires certain arguments to be passed to the constructor. However, I am exposing a simplified API to customers. My internal class looks something like this: class Foo { ...
JDB's user avatar
  • 25.9k
1 vote
1 answer
2k views

how to override class methods using javascript proxy

this is my class class Chrome { constructor(browser, page) { this.browser; this.page; } async launch() { if (!this.browser) { console.log("launching browser..."); this....
Ashik's user avatar
  • 3,258
1 vote
1 answer
508 views

Custom elements with proxied has, get & set

My goal is to create a class ObservableElement extending HTMLElement such that it can be used to define custom elements, e g: customElements.define('an-observable-elem', class extends ...
Zach's user avatar
  • 85
0 votes
0 answers
1k views

How to use Proxy to intercept every function of an object in JavaScript or E6?

I have a class A, defined like below.(All sample code is simplified for privacy) class A{ Func1(){ } Func2(){ } Func3(){ } } And I want to make every function in A ...
vainman's user avatar
  • 427
4 votes
2 answers
2k views

How to wrap object being constructed with Proxy inside constructor?

I understand that Proxy can be used to alter object-level behaviors, such as bracket notation get and set. All the examples I can find show constructing an object and then wrapping it with a Proxy ...
Ming's user avatar
  • 1,653
0 votes
1 answer
349 views

javascript create dynamic class by object

Task: I want to create a dynamic class by a given JSON Object in ES6. After a lot of reading in the MDN web docs and much stackoverflow questions i'm totally confused how to get this work. JSON ...
Kneggebrot's user avatar
1 vote
1 answer
677 views

sessionStorage proxy class scope

I am wondering how to access the native sessionStorage scope from within my custom methods. My example: https://jsfiddle.net/3mc7ao7j/1/ At line 3 I would like to be able to proxy through to my ...
Stephan-v's user avatar
  • 20k
17 votes
1 answer
3k views

How to Proxy Custom Element (Web Component)

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
0 votes
1 answer
339 views

Why can’t a proxy trap invoke Function.prototype.apply to construct an ES6 class?

I'm trying to Proxy a ES6 constructor (mostly trying to emulate Python's descriptors for fun and learning): class _Record { constructor(data) { this._data = data; } } const ...
art-solopov's user avatar
  • 4,617
2 votes
0 answers
357 views

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 ...
phoboslab's user avatar

15 30 50 per page