tags:

views:

111

answers:

4

Hi,

I think Javascript is a fantastic language. I like all the little peculiarities, the inheritance model, the lack of classes, etc. Because of this I have never wanted to learn a framework as all of the ones I've looked at (jQuery, MooTools, Prototype, Dojo) force you to change how you write your code, in many cases it's not really even Javascript anymore.

Yet, I feel the same frustration every time I have to implement something as fundamental as a hash table or a linked list. Sure, I write it once and never again, but given how many times these structures have been coded by other people before me I really shouldn't have to.

Are there any "pure" Javascript libraries that will give you a bunch of basic data structures and utilities, similar to what you find in java.util? Again, I don't want anything that changes the way I code, I want to use these objects within vanilla Javascript.

Thanks

+2  A: 

Maybe not really what you were looking for, but you might be interested in the Google Web Toolkit.

The GWT is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java.

One of the main components of GWT is the "JRE emulation library", a library of JavaScript implementations of the commonly used classes in the Java standard class library, such as most of the java.lang package classes and a subset of the java.util package classes.

"In many cases it's not really even JavaScript anymore"... Note that this is literally the case with GWT, but I believe it deserves to be mentioned in this question.

Daniel Vassallo
Thank you, I've had a brief look at it. It sure is something, especially the compilation. Not quite what I'm looking for, but like you said, definitely worth a mention.
Andreas Jansson
+5  A: 

Google's Closure library has lots of data structures in it. The API documentation is at http://closure-library.googlecode.com/svn/docs/index.html (check the goog.structs "package").

Matthew Crumley
Thank you, this is excellent!
Andreas Jansson
Actually, I'm marking this as the answer, not only because of the data structures Closure provides, but because it seems to be just what I'm looking for - a Javascript library that does the tedious tasks for you, but is not a framework.
Andreas Jansson
+1  A: 

Frankly, I think you're crazy for not wanting to look into jQuery or Prototype or just about any web framework, but if you want pure coding-oriented stuff you might look at Functional.js: http://osteele.com/sources/javascript/functional/

In my opinion most of the "data structure" stuff in the Java libraries really isn't appropriate for Javascript in any direct way. One of the most important epiphanies I had when learning Javascript was to really "get" that Javascript is nothing like Java, and one of the first steps on the path to enlightenment is to stop trying to make it be like Java.

Pointy
Data structures don't have anything to do with Java. I do agree with you that in most cases, you don't need anything more than arrays and objects in JavaScript though... and about using frameworks.
Matthew Crumley
Ok well sure, but what I meant was that the overall architecture of java.util and java.text and etc. really is a bad fit for Javascript.
Pointy
Yeah, I wouldn't want a copy of java.util.*. I just mean that the basic data structures -- trees, lists (although, most of the time arrays are fine), priority queue's, etc. -- are definitely applicable for some types of programs.
Matthew Crumley
A: 

I've written a standalone JavaScript implementation of a hash table that is certainly influenced by Java's Hashtable: http://www.timdown.co.uk/jshashtable. I've also now added an implementation of HashSet.

Tim Down