如何判断哪个类调用了函数

发布于 2024-08-29 03:19:55 字数 341 浏览 4 评论 0原文

我目前正在开发 Flex 前端,并一直在使用 Parsley 框架来传递周围的消息/事件。

我想知道函数(在本例中为事件的构造函数)是否有一种简单的方法来获取对调用它的对象的引用?

这是为了确保我定义的某个事件只能由一个指定的类调度。我的想法是以某种方式检查构造函数的调用者,如果类型不正确则抛出错误。

我愿意接受这里的替代方法的建议,但如果可能的话,我理想地希望坚持使用 Parsley 'MessageHandler' 方法。

感谢各位的阅读..

I am working on a Flex Front End at the moment, and have been using the Parsley framework for passing messages/events around.

I was wondering if there is a simple way for a function (in this case, an event's constructor) to obtain a reference to the object which called it?

This is to ensure that a certain event that I am defining can only be dispatched by one specified class. My thinking is to check the caller of the constructor somehow, and throw an error if it is not of the correct type.

I am open to suggestions of alternative approaches here, but I would ideally like to stick to using the Parsley 'MessageHandler' approach if at all possible.

Thanks for reading guys..

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

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

发布评论

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

评论(2

盗心人 2024-09-05 03:19:55

堆栈跟踪有效,但您可以更轻松地将调用者的引用传递给函数并对其进行类型检查。

function dispatchEvent(caller:*):void {
   if(caller is SpecificClass) {
      // then dispatch event
   }
}

Stack trace works, but you could much more easily pass a reference to the caller to the function and type check it.

function dispatchEvent(caller:*):void {
   if(caller is SpecificClass) {
      // then dispatch event
   }
}
别忘他 2024-09-05 03:19:55

免责声明:我对欧芹不熟悉。

请参阅actionscript 3 中的堆栈跟踪。您可以从堆栈跟踪中获取调用者函数。

但有一件事......堆栈跟踪只能在调试模式下检测到,据我所知,没有办法让调用者进入“生产”模式。

Disclaimer: I'm not familiar with Parsley.

See stack trace in actionscript 3. You can get the caller function from the stack trace.

There is one thing though.. The stack trace can only be detected in debug mode and to my knowledge there is no way to get the caller in "production" mode.

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