I'm looking for a way to get the return expression of a function in Javascript. I'm expecting to get it as a string but any type would do. Also, I'm looking for a way to set the return statement of a function without affecting the rest of it.
Example:
let f1 = () => {
let x = 1
return 2 + x
}
let f2 = () => {
let y = 2
return 3 + y
}
let s = f1.getReturnExpression()
console.log(s) // 2 + x
f2.setReturnExpression(s)
console.log(f2.toString()) // "function f2() { let y = 2; return 2 + x; }
Aucun commentaire:
Enregistrer un commentaire