4 ms·
For the record, the reason why Underscore.js is namespaced in the way it is has everything to do with compatibility and future proofing. It was extracted from
by jashkenas 15y ago
For the record, the reason why Underscore.js is namespaced in the way it is has everything to do with compatibility and future proofing.
It was extracted from the DocumentCloud codebase, so it had to be possible to embed directly in the website of any major news organization ... without conflicting with any of their JavaScript already on the page. For example:
http://thecaucus.blogs.nytimes.com/2011/07/31/boehner-outlines-debt-agreement/ http://thecaucus.blogs.nytimes.com/2011/07/31/boehner-outlin...
... the embedded doc still works, even though Prototype.js happens to be on that page, and has already patched in `Array.prototype.each`.
- jdd 15y ago@jashkenas I think your example just happened to not have problems. Underscore.js still has problems (https://github.com/documentcloud/underscore/issues/7 https://github.com/documentcloud/underscore/issues/7) with Prototype.js. I have made a small test (http://dl.dropbox.com/u/513327/underscore_prototype_compat.html http://dl.dropbox.com/u/513327/underscore_prototype_compat.h...) to show some of the potential issues.