I decided to indulge in TypeScript and es6, and in particular Proxy.

The problem is that in the debugger (Edge) both the content and the length of the arguments are shown, but in the code all methods for converting to the array are returned [] or calls to the length return 0.

class Item { constructor(public resolve: any, public value: any) { }; } class CounterComponent { public currentCount: any; private dictionary = {}; private proxy: any; constructor() { this.SetProxy(); } private SetProxy(): void { this.proxy = new Proxy({}, { get: (rcvr, name) => { return () => { let args: Array<any> = []; let length = arguments.length; //length==0 let args1 = [...arguments]; //args1==[] for (let i = 0; i < arguments.length; i++) { args.push(arguments[i]); } let promise = new Promise((resolve, reject) => { // resolve(123); let item = new Item(resolve, args); this.dictionary[name] = item; }); return promise; }; } }); } public async CallMethodAsync() { this.currentCount = await this.proxy.AllHello("Всем Привет"); } public setResult(): void { let key: string; for (let name in this.dictionary) { key = name; } let item = <Item>this.dictionary[key]; item.resolve(item.value); } } 

At the same time await fulfills. And is there any analogue of the C # finalizer to understand when an object is subject to garbage collection?

  • four
    arrows do not have arguments, that is, in your case you get arguments from SetProxy - Grundy
  • And is there any analogue of the C # finalizer to understand when an object is subject to garbage collection? - not. - Grundy
  • In ES6 there is the main thing that in the debugger, then ((Edge) shows the contents - Serginio
  • Which of the two comments did you answer? - Grundy
  • @ Grundy thanks, but how to get out in the first and second case? This is where soft.vub.ac.be/~tvcutsem/proxies type arguments get - Serginio

1 answer 1

The problem is that one of the limitations of the switch functions

Does not have its own arguments object

Arrow functions do not have their own arguments object, so in the body of arrow functions, arguments will refer to a variable in the surrounding area.


The simplest solution is to use a non- switch function, for example

 get: (rcvr, name) => { return function() { let args: Array<any> = []; ... } } 

Alternative solution: use rest parameters

 get: (rcvr, name) => { return (...args)=>{ ... } } 

In this case, args already an array and you can work with it immediately without additional operations.

  • Thanks for checking now - Serginio
  • Thank you so much! - Serginio