RE: [flexcoders] function.apply() and "this" on instance method
No, not on class methods From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of herrodius Sent: Tuesday, August 28, 2007 2:58 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] function.apply() and "this" on instance method Hi all, I was wondering if there would be any way of forcing the "this" parameter on function.apply() to actually point to the parameter passed and not to the instance of the class that contains the invoked method. I read some posts that say it will only work with functions defined as Function, but unfortunately that doesn't help me any further. What I want to do is alter the behavior of existing methods at runtime. For instance, I gave an instance of a class that implements IResponder, and I would like to execute some code before and after the invocation of the result and fault methods. Any ideas are greatly appreciated. thx, Christophe
Re: [flexcoders] function.apply() and "this" on instance method
Hi, To address your case of wanting to execute code before and after the fault and result methods of IResponder, would it be sufficient to create an implementation of IResponder that takes another IResponder and wraps that object's fault and response methods. Something like: class ResponderWrapper implements IResponder { private var _wrappedResponder; public ResponderWrapper(wrapped:IResponder) { _wrappedResponder = wrapped; } public function fault() { // your pre-execution code here _wrappedResponder.fault() // your post-execution code here } // and similarly for result. } You then use ResponderWrapper in place of the 'wrapped' IResponder. Further flexibility could be achieved by passing in additional parameters that are functions defining the pre and post execution operations when constructing this object. I have found this kind of 'decorator' approach quite useful in the past. Regarding the use of 'apply' - I think you are correct that you cannot use 'apply' on a method, for methods 'this' always is the owning object, even if you are referring to a method via a variable of type function. HTH Stephen
[flexcoders] function.apply() and "this" on instance method
Hi all, I was wondering if there would be any way of forcing the "this" parameter on function.apply() to actually point to the parameter passed and not to the instance of the class that contains the invoked method. I read some posts that say it will only work with functions defined as Function, but unfortunately that doesn't help me any further. What I want to do is alter the behavior of existing methods at runtime. For instance, I gave an instance of a class that implements IResponder, and I would like to execute some code before and after the invocation of the result and fault methods. Any ideas are greatly appreciated. thx, Christophe