转发变量参数

发布于 2024-07-27 19:54:20 字数 624 浏览 1 评论 0原文

我将对远程服务的调用封装在我自己的 RemoteObject 类中。 这一切都工作正常,除非我必须处理传递给远程调用的变量参数。 由于这是对 NetConnection.call 的调用,我应该能够传递变量参数,但由于我封装了 NetConnection.call ,所以它会抛出错误。 这就是我的方法当前的样子:

public function call( method : String, callback : Function, ... args ) : void
{
    var responder : Responder;

    responder = new Responder( callback, onResponderStatus );

    this._nc.call( this._remoteObject + "." + method, responder, args );
}

如您所见,我的方法采用可变参数作为最后一个参数。 我试图将这些参数传递给 NetConnection.call 方法。 但是,在我的方法的范围内,args 将是 Array 类型。 如何正确地将变量参数转发给 NetConnection.call

I'm encapsulating a call to a remoting service in my own RemoteObject class. This all works fine except when I have to deal with variable parameters that are being passed to the remote call. Since this is a call to the NetConnection.call, I should be able to pass variable arguments but since I'm encapsulating the NetConnection.call it's throwing up errors. This is what my method currently looks like:

public function call( method : String, callback : Function, ... args ) : void
{
    var responder : Responder;

    responder = new Responder( callback, onResponderStatus );

    this._nc.call( this._remoteObject + "." + method, responder, args );
}

As you can see, my method takes a variable arguments parameter as the last parameter. I'm trying to pass these parameters to the NetConnection.call method. But, within the scope of my method, args would be of type Array. How do I properly forward the variable arguments to NetConnection.call?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她说她爱他 2024-08-03 19:54:20

函数::apply 是你正在寻找的......最后,它应该看起来像这样:

this._nc.call.apply(this._nc, [this._remoteObject + "." + method, responder].concat(args) );

greetz

back2dos

Function::apply is what you are looking for ... in the end, it should look like this:

this._nc.call.apply(this._nc, [this._remoteObject + "." + method, responder].concat(args) );

greetz

back2dos

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文