dimanche 7 octobre 2018

Adding decorators to dynamically created functions in typescript

I am creating dynamic functions in typescript. On these dynamic functions, I want to add decorators. What is the best way to achieve this scenario? Is this a possibility?

Eg - Want to achieve something like this

@log
@requiredOption
var dynamicFunction = new Function('a', 'b', 'return a + b');
alert(dynamicFunction(2, 3));

Also, if I am creating multiple dynamic functions, how do I add decorators on them?

eg.

var dynamicFunction:Array<Functions>; 
for (i=0; i<10; i++){
@log
@requiredOption
dynamicFunction[i] = new Function('a','b','return a+b');
}





Aucun commentaire:

Enregistrer un commentaire