ActionScript - 重写方法而不匹配签名?
扩展类时,是否无法在不匹配参数的情况下重写方法?
例如,我想使用方法的名称,在本例中它是一个套接字扩展,我想要覆盖的方法是 connect
。但是,我想请求库存 connect
函数不请求的其他参数。
是使用自己的参数创建我自己的类似连接方法的唯一替代方法,从该函数调用 super.connect 并覆盖 stock 连接函数以在调用时抛出错误?
这一切听起来就像火车失事一样。
when extending a class, is it impossible to override a method without also matching the parameters?
for example, i'd like to use the method's name, in this case it's a socket extension and the method i want to override is connect
. however, i want to request additional parameters that the stock connect
function does not request.
is the only alternative to create my own connect-like method with my own parameters, call super.connect
from this function and override the stock connect function to throw an error if it's called?
that all kind of sounds like a train wreck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ActionScript 不支持函数重载(但是 Darron Schall 证明了某种 中的伪重载这篇文章)。
我认为在你的情况下,只剩下创建你自己的 connectEx 方法了。
Function overloading is not supported in ActionScript (however Darron Schall demonstrated some kind of pseudo overloading in this article).
I think in your case it's only left over to create your own
connectEx
method.遗憾的是,不支持重载。作为下一个最佳选择,您可以考虑可选参数。这将允许您向方法传递尽可能少或任意多的参数。该方法将接收数组中的这些参数,从那时起您可以按照您想要的方式处理它们。
使用可选参数的方法如下所示:
您可以在此处阅读有关可选参数的更多信息。
Sadly, overloading is not supported. As a next best option, you could consider optional arguments. This would allow you to pass as few or as many params as you want to a method. The method would receive these params in an array and you could handle them however you want from that point on.
Here's how a method using optional params would look:
You can read more about optional parameters here.