jeudi 12 septembre 2019

Get class constructor argument names

I'm implementing a certain dependency injection solution for ES classes, and for it I need to know exact names of class constructor parameters.

When I get string form of class or class static method, it does give full code (as usually for functions), but for class constructor it does not.

class C { constructor(a, b) { }; static m(x,y) { } }
console.log(C);
console.log(C.constructor);
console.log(C.m);

results in

class C { constructor(a, b) { }; static m(x,y) { } }
ƒ Function() { [native code] }
ƒ m(x,y) { }

As result, I have to parse whole class code to extract constructor arguments part.

Is there any cleaner way to get constructor argument names?





Aucun commentaire:

Enregistrer un commentaire