Generics
There are 2 entries for the tag
Generics
download source code
download this article in .doc format.
Overview
In a recent article I presented a simple implementation of a generic type system in JavaScript. Please see that document for a detailed enumeration of the motivations and benefits, including type safetly and Visual Studio intellisense support.
In this document I will present a 'better' implementation that eliminates many of the limitations of my 'simple' generic type implementation.
I will also provide a starter library of generic compatible collections including Queue, ListArray and Dictionary that you may use immediately and that can serve as a reference for implementing your own generic types in JavaScript.
Features:
...
source and demo
What are 'generic types'?
A generic type is defined using one or more type variables and has one or more methods that use a type variable as a placeholder for an argument or return type. For example, the type java.util.List<E> is a generic type: a list that holds elements of some type represented by the placeholder E. This type has a method named add(), declared to take an argument of type E, and a method named get(), declared to return a value of type E. source
Why attempt this in JavaScript?
My answer is two-fold. Primarily for type safety. While the...