0
MyObj = 
{
    ajax: null,
    init: function()
    {
        this.ajax = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
           .createInstance();
        this.ajax.onload = function()
        {
            return function() {this.onload.apply(this, [null]);}
        };
    },
    onload: function ()
    {
        Reader.log("I really hope I can use `this.ajax` here");
    }
}

isn't it correct way to bind onload to MyObj? For some reason onload never called. However if I avoid binding and just put this.ajax.onload = this.onload then onload invoked. How to get binding work?

1 Answer 1

1

and I will answer myself...

I should have called the function

var me = this;

this.ajax.onload = (function()
        {
            return function() {me.onload.apply(me, [null]);}
        })();
Sign up to request clarification or add additional context in comments.

2 Comments

Why the extra function wrapper there? this.ajax.onload = function() {me.onload.apply(me, [null]);}
@ Joshua: You are right, that was unnecessary and it worked even without it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.