我有implments一堆這些通用<T>
數據結構的一個項目:
- Linked List
- Dictionary
- Multi Dictionary
- Binary Search Tree
- Stack
- Queue
- Set
- Bag
- Binary Heap
- Priority Queue
來源:https://github.com/basarat/typescript-collections
例如一套:
/// <reference path="collections.ts" />
var x = new collections.Set<number>();
x.add(123);
x.add(123); // Duplicates not allowed in a set so will get filtered out
// The following will give error due to wrong type:
// x.add("asdf"); // Can only add numbers since that is the type argument.
var y = new collections.Set<number>();
y.add(456);
x.union(y);
console.log(x.toString()); // [123,456]
我認爲最接近的微軟每一個來創建一個非常淺的通用.NET模式仿真是當他們建立微軟的Ajax庫:http://msdn.microsoft.com/en-us/庫/ bb397536(v = VS.100)的.aspx。更好的事情是考慮是否需要,因爲在基本的JavaScript Array中有很多好處。 – WiredPrairie