JavaScript Collections API?

后端 未结 6 866
再見小時候
再見小時候 2021-02-15 12:20

I\'ve searched quite a while for a Collections API (list, set) for JS and surprisingly I could only this: http://www.coffeeblack.org/work/jscollections/

This is exactly

相关标签:
6条回答
  • 2021-02-15 12:57

    You can also try buckets, it has the most used collections.

    0 讨论(0)
  • 2021-02-15 13:06

    You can try js_cols, a collections library for JavaScript.

    0 讨论(0)
  • 2021-02-15 13:06

    Can't you use the jquery collection plugin.

    http://plugins.jquery.com/project/Collection

    0 讨论(0)
  • 2021-02-15 13:15

    jQuery's primary focus is the DOM. It doesn't and shouldn't try and be all things to all people, so it doesn't have much in the way of collections support.

    For maps and sets, I'd like to shamelessly point you in the direction of my own implementations of these: http://code.google.com/p/jshashtable/

    Regarding lists, Array provides much of what you need. Like most methods you might want for arrays, you can knock together a contains() method in a few lines (most of which are to deal with IE <= 8's lack of support for the indexOf() method):

    Array.prototype.contains = Array.prototype.indexOf ?
        function(val) {
            return this.indexOf(val) > -1;
        } :
        function(val) {
            var i = this.length;
            while (i--) {
                if (this[i] === val) {
                    return true;
                }
            }
            return false;
        };
    
    ["a", "b", "c"].contains("a"); // true
    
    0 讨论(0)
  • 2021-02-15 13:15

    Since javascript have both arrays [] and associative arrays {}, most needs for datstructures are already solved. The array solves the ordered list, fast access by numeric index whilst the associative array can be considered a unordered hashmap and solves the fast access by string keys.

    For me that covers 95% of my data structure needs.

    0 讨论(0)
  • 2021-02-15 13:23

    If you get some free time you can checkout. https://github.com/somnathpanja/jscollection

    0 讨论(0)
提交回复
热议问题