[]TypeScript 泛形方法如何传TYPE?
GetComponetInChild(node:laya.display.Node):Laya.Animator
{
for (var index = 0; index < node._childs.length; index++) {
var element:Laya.Animator = node._childs[index].getComponentByType(Laya.Animator);
if (element!=null)
{
return element;
}else
this.GetComponetInChild(node._childs[index],);
}
}
如何写成泛型方法呢???编译不通过
GetComponetInChild<T>(node:laya.display.Node):T
{
// var s:=typeof(Laya.Animator);
for (var index = 0; index < node._childs.length; index++) {
var element:Laya.Animator = node._childs[index].getComponentByType(T);
if (element!=null)
{
return element;
}else
this.GetComponetInChild(node._childs[index],);
}
}
{
for (var index = 0; index < node._childs.length; index++) {
var element:Laya.Animator = node._childs[index].getComponentByType(Laya.Animator);
if (element!=null)
{
return element;
}else
this.GetComponetInChild(node._childs[index],);
}
}
如何写成泛型方法呢???编译不通过
GetComponetInChild<T>(node:laya.display.Node):T
{
// var s:=typeof(Laya.Animator);
for (var index = 0; index < node._childs.length; index++) {
var element:Laya.Animator = node._childs[index].getComponentByType(T);
if (element!=null)
{
return element;
}else
this.GetComponetInChild(node._childs[index],);
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Aar0n
赞同来自: