Given “/users/:id”, what’s the right JS approach to generate a function `foo` such that `foo({id: 42})` produces the string “/users/42”?
Current attempt https://is.gd/GCYWD0 — involves `new Function` and building code from strings — yuck. There’s a better way?
-
-
Why not just return a lambda? Do you _need_ the function body to be 'compiled'?
-
Good point! After sleeping on it, I realized I could probably close over the stuff I needed. Is there a benefit to “compiling”?
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.