4 ms·
I just gave the code a quick look and I find this `eval` usage not too cool: https://github.com/harthur/replace/blob/master/replace.js#L41-43 https://github.co
by fernandezpablo 14y ago
I just gave the code a quick look and I find this `eval` usage not too cool:
https://github.com/harthur/replace/blob/master/replace.js#L41-43 https://github.com/harthur/replace/blob/master/replace.js#L4...
It relies on the fact that you can provide javascripts String#replace a "replace function" (1). The author just evals the contents of a command line provided file into a variable called `replaceFunc`.
Beside that, there's not a lot that can be pointed out as "bad", at least by just reading it lightly (5-10 mins).
[1] https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...
- VMG 14y agoIt might not be optimal but the set goal couldn't be achieved differently without much overhead. It's a valid use of eval in my opinion.
- klibertp 14y agoAs VMG writes, it's one of a few places where 'eval' is the right tool for the job. In this case you either have to drop the feature (of providing replacement function), implement your own language/DSL that compiles down to JS function or just use eval. What would you do in this case?