-
-
Save disco0/dd6d60092e3a960edfeac14a2ae98b2b to your computer and use it in GitHub Desktop.
Virtualizing TypeScript Properties with Proxy and Decorator - listing 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VirtHandler | |
{ | |
target: any; | |
get( t: any, p: PropertyKey, r: any): any | |
{ | |
return this.target[p]; | |
} | |
} | |
class Base | |
{ | |
static handler = new VirtHandler(); | |
static createProxy( v: any) | |
{ | |
this.handler.target = v; | |
return new Proxy( v, this.handler); | |
} | |
first = Base.createProxy( { v: 1 }); | |
second = this.first; | |
} | |
class Derived extends Base | |
{ | |
first = Base.createProxy( { v: 2 });; | |
} | |
let obj = new Derived(); | |
console.log( obj.second.v); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment