Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
991 views
in Technique[技术] by (71.8m points)

underscore.js - Are the `escape` and `unescape` functions of `underscore` and `lodash` the same?

Are the escape and unescape functions of underscore and lodash the same? So can I escape with lodash and unescape with underscore and always get the same string?

I may want to switch from vanilla https://stackoverflow.com/a/12034334/1707015 to https://stackoverflow.com/a/18756038/1707015 and have to connect different components.

question from:https://stackoverflow.com/questions/65834423/are-the-escape-and-unescape-functions-of-underscore-and-lodash-the-same

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Apart from the fact that Underscore escapes backticks and Lodash doesn't, they serve the same purpose and are interchangeable.

The second answer you're linking to contains a remark that Lodash offers the same API as Underscore, but is written to be more performant. I should point out that this remark is no longer true, if it has ever been.

Right from the start, Lodash has diverged significantly from Underscore, introducing more breaking changes with every major release. Although many functions are still roughly the same (such as escape) the libraries are not interchangeable in general nowadays.

The performance advantage should also be taken with a grain of salt. While Lodash does prioritize performance more than Underscore, most applications will not notice the difference, and there is also some anecdotal evidence of applications actually being a little bit faster with Underscore. Lodash is also four times larger than Underscore. So for a performance-based decision, you should benchmark your application with both libraries (which is not easy in general, given that they are not entirely interchangeable) and then weigh the speed difference against the size difference.

So choose wisely!

Full disclosure: I'm the maintainer of Underscore.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...