Hi,
I do it everytime like this:
var MyClass = function() {
this.varA = 1;
this.varB = true;
}
Object.extend(MyClass.prototype, {
callback: function(res) {
alert(res.value);
alert(this.varA); // this is now working!!!
},
start: function() {
Namespace.ClassName.AjaxMethod(a, b, c, this.callback.bind(this));
}
});
var x = new MyClass();
x.start();
Regards,
Michael
On 9/27/06, INeedADip <[EMAIL PROTECTED]> wrote:
>
> Is there a simple way to have the callback execute within a particular
> scope?
>
> Here is what I would like to do:
>
> MyObj = function() {
> var something;
> return {
> init: function() { ... },
> performAjax : function(){
> NameSpace.Page.AjaxProMethod(params, this.ajaxCallback);
> },
> ajaxCallback : function(res){
> something = res.value;
> this.anotherMethod();
> },
> anotherMethod : function() {....}
> }
> }
>
> "this.anotherMethod()" will blow up because "this" doesn't refer to
> MyObj because the function was executed in a different scope.
>
> I'm sure my syntax is off, but hopefully you get the point. In the
> Yahoo UI you can listen to events and what not while passing in the
> scope like:
>
> Something.addListener(window, 'load', 'callbackfunctin', this, true);
>
> 'this' is a parameter you pass, and the last parameter 'true' means
> that 'callbackfunction' will be called in the scope of 'this'.
>
> It would be great to have something like this in AjaxPro, maybe
> something like:
> NameSpace.Page.Method.(parameters, <function> callback, <object>
> scope);
> ...or something like that.
>
> I'm just bitching though..I've worked around it many, many times, it
> just makes the JavaScript a little uglier.
>
> Reference:
> http://developer.yahoo.com/yui/docs/event/YAHOO.util.Event.html#addListener
>
>
> >
>
--
Best regards | Schöne Grüße
Michael
Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer
http://weblogs.asp.net/mschwarz/
http://www.schwarz-interactive.de/
Skype: callto:schwarz-interactive
MSN IM: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ajax.NET Professional" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/ajaxpro
The latest downloads of Ajax.NET Professional can be found at
http://www.ajaxpro.info/
Don't forget to read my blog at http://weblogs.asp.net/mschwarz/
-~----------~----~----~----~------~----~------~--~---