Parametric Polymorphism (Generic Programming) not supported in Javascript?
I cannot f开发者_开发百科ind any information on Generic Programming in Javascript. So I assume it is not supported. Is it true? Is there anything that comes close?
Parametric Polymorphism http://en.wikipedia.org/wiki/Parametric_polymorphism
Generic Programming http://en.wikipedia.org/wiki/Generic_programming
JavaScript is dynamically duck typed. Generics don't make sense in that context. There aren't static types. It being supported or not is nonsensical.
Are you looking for something like:
var fn = function<T>(p1) {
var elmt = document.getElementById(typeof(T).toString());
[...]
}
I think that's is not supported by JavaScript/ECMA-262: ECMAScript specification.
You may want to take a look at this JavaScript generic type implementation.
精彩评论