开发者

Parametric Polymorphism (Generic Programming) not supported in Javascript?

开发者 https://www.devze.com 2023-03-20 04:36 出处:网络
I cannot f开发者_开发百科ind any information on Generic Programming in Javascript. So I assume it is not supported.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号