6 ms·
Underscore.js: Annotated Source Code
- helium 16y agoI wish more open source libraries had this. This seems to be a trend in the javascript ecosystems. Coffeescript also has this. http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/
- shawndumas 16y agoSame author; the venerable Jeremy Ashkenas[1]. And yes; quality is fractal. ---- [1]: http://github.com/jashkenas http://github.com/jashkenas
- lux 16y agoI'd love to know if there's a lib for generating annotations like this from source comments. I've always loved docs tha include the code for reference, helps to see what's actually going on :)
- sant0sk1 16y agohttp://github.com/jashkenas/docco http://github.com/jashkenas/docco http://github.com/rtomayko/rocco http://github.com/rtomayko/rocco http://github.com/rtomayko/shocco http://github.com/rtomayko/shocco
- jashkenas 16y agoDocco is CoffeeScript/JavaScript, Rocco is Ruby, Shocco is Shell, and there's one more (that I know of) ... Pycco for Python: http://github.com/fitzgen/pycco http://github.com/fitzgen/pycco And a first cousin, once removed: Dox (JavaScript): http://visionmedia.github.com/dox/ http://visionmedia.github.com/dox/
- jacobolus 16y agoDox seems to just be explicitly marked documentation, not every comment. Pycco claims to support Python, Ruby, JavaScript, CoffeeScript, Scheme, and Lua.
- shawndumas 16y agoI just submitted one earlier this morning[1]. ----- [1]: http://news.ycombinator.com/item?id=1767758 http://news.ycombinator.com/item?id=1767758
- moron4hire 16y agoThis is just a style comment, but given JavaScript's open class prototypes and expando objects, I generally prefer to write these methods as new members on their natural classes. For example, the RegEx escape method would be on the RegEx class itself, rather than being a stand alone function. Other than that, this is an incredibly useful set of functions that any JavaScript developer should have in their toolkit.
- rtp 16y agoYou mean like putting the methods into the native classes' prototypes? That's a bad idea. The reason why it is a bad idea is that you cannot extend a prototype only within a scope, i.e if you change the prototype, it'll be changed regardless of whether it'll break another library, or that another library replaces your methods and thus render your library broken. This opens up the risk that you'll end up with bugs that are hard to trace to their source.
- luigi 16y agoNext to jQuery, Underscore is my most-used JS library. Makes scripting client-side behavior so much more pleasant.
- shawndumas 16y ago"It's the tie to go along with jQuery's tux."[1] ----- [1]: http://documentcloud.github.com/underscore/ http://documentcloud.github.com/underscore/
- chewbranca 16y agoI don't understand this statement. Initially when I saw underscore.js a few weeks ago, I was under the impression it was a light weight js library for when you didn't want to use jquery or something even heavier. Do you use this in conjunction with jquery? Could someone please explain the use case for this library as their is a fair bit of duplication between this and jquery.
- jashkenas 16y agoUnderscore is intended to fit in nicely alongside jQuery -- in the handful of places where the two overlap (map, each, bind), Underscore delegates to the native browser implementations, providing quite a substantial performance boost over the jQuery versions. There is a benchmark script at the bottom of this page, and you can run it in your browser to see the difference: http://documentcloud.github.com/underscore/test/test.html http://documentcloud.github.com/underscore/test/test.html In general, Underscore is intended for logic and data manipulation, and jQuery handles the DOM and Ajax calls.
- chewbranca 16y agoThank you for clarifying, I appreciate it. There are some very nice data manipulation functions in underscore, and its speed is impressive. I will definitely look into it more.
- pyronicide 16y ago